<?php
header("Content-Type:text/html;charset=UTF-8");
$num=['A','2','3','4','5','6','7','8','9','10','J','Q','K'];
$icon=['♠'=>'red','♥'=>'red','♦'=>'black','♣'=>'black'];
$poker=array();
foreach ($icon as $key => $v1) {foreach ($num as $v2) {$poker[]="<font color='".$v1."'>$v2 $key</font>";# code...}
}// 通过数组赋值的方式添加两个元素 大小王两张牌 大王红色 小王黑;$poker[]="<font color='red'>大王</font>";$poker[]="<font color='black'>小王</font>";print_r($poker);
echo '<hr>';
shuffle($poker);
print_r($poker);
// 使用随机函数rand()生成一个数
echo $m=rand(0,2);
switch ($m) {case 0:echo "恭喜玩家A抢得地主!发牌20张";break;case 1:echo "恭喜玩家B抢得地主!发牌20张";break;case 2:echo "恭喜玩家c抢得地主!发牌20张";break;}
$max=17;
echo '<hr>';
?><!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>随机发牌</title>
</head>
<style type="text/css">div{margin: 15px 0;}tr{height:60px;}td{border: 1px solid #ccc;width: 40px;padding: 6px 3px;}</style>
<body>
<div>玩家A的牌组</div>
<?phpecho '<table><tr>';
if ($m==0) {
$max=20;
}else
{$max=17;}for ($i=1; $i<=$max; $i++) {echo "<td>".current($poker).'</td>';next($poker) ;
}
echo "</tr></table>";?>
<div>玩家B的牌组</div>
<?phpecho '<table><tr>';
if ($m==1) {
$max=20;
}else
{$max=17;}for ($i=1; $i<=$max; $i++) {echo "<td>".current($poker).'</td>';next($poker) ;
}
echo "</tr></table>";?>
<div>玩家c的牌组</div>
<?phpecho '<table><tr>';
if ($m==2) {
$max=20;
}
else
{$max=17;}for ($i=1; $i<=$max; $i++) {echo "<td>".current($poker).'</td>';next($poker) ;
}
echo "</tr></table>";?>
</body>
</html>