閑來無聊,就寫了這個(gè)方法,也算是熟悉下php的數(shù)組操作,還請各位大神多指教。$arr 數(shù)組,好像有點(diǎn)問題,應(yīng)該 2=>'方片2',3=>'梅花2',4=>'紅心2',5=>'黑桃2', 等的順序換下??磥砼拼蛏倭?。估計(jì)這個(gè)方法,一般程序都不會(huì)用吧。
?php
wash_card();
function wash_card(){
$tmp = $arr = array(
0=>'大王',1=>'小王',
2=>'方片2',3=>'梅花2',4=>'紅心2',5=>'黑桃2',
6=>'方片A',7=>'梅花A',8=>'紅心A',9=>'黑桃A',
10=>'方片K',11=>'梅花K',12=>'紅心K',13=>'黑桃K',
14=>'方片Q',15=>'梅花Q',16=>'紅心Q',17=>'黑桃Q',
18=>'方片J',19=>'梅花J',20=>'紅心J',21=>'黑桃J',
22=>'方片10',23=>'梅花10',24=>'紅心10',25=>'黑桃10',
26=>'方片9',27=>'梅花9',28=>'紅心9',29=>'黑桃9',
30=>'方片8',31=>'梅花8',32=>'紅心8',33=>'黑桃8',
34=>'方片7',35=>'梅花7',36=>'紅心7',37=>'黑桃7',
38=>'方片6',39=>'梅花6',40=>'紅心6',41=>'黑桃6',
42=>'方片5',43=>'梅花5',44=>'紅心5',45=>'黑桃5',
46=>'方片4',47=>'梅花4',48=>'紅心4',49=>'黑桃4',
50=>'方片3',51=>'梅花3',52=>'紅心3',53=>'黑桃3',
);
foreach($arr as $k=>$v){
$index = rand(0,54 - $k -1);
$key = array_search($tmp[$index], $arr);
$cards[$key] = $tmp[$index];
unset($tmp[$index]);
$tmp = array_values($tmp);
}
$landowner = array(0=>'用戶一',1=>'用戶二',2=>'用戶三');
$lk = rand(0,2);
echo '本輪地主: '.$landowner[$lk].'br >';
$card['landwehr']['cards'] = array_slice($cards, 0, 3, true);
ksort($card['landwehr']['cards']);
echo '地主: '.implode(' ',$card['landwehr']['cards']).'br >';
$card['user1']['cards'] = array_slice($cards, 3, 17, true);
ksort($card['user1']['cards']);
echo '用戶一: '.implode(' ',$card['user1']['cards']).'br >';
$card['user2']['cards'] =array_slice($cards, 20, 17, true);
ksort($card['user2']['cards']);
echo '用戶二: '.implode(' ',$card['user2']['cards']).'br >';
$card['user3']['cards'] = array_slice($cards, 37, 17, true);
ksort($card['user3']['cards']);
echo '用戶三: '.implode(' ',$card['user3']['cards']).'br >';
}
?>