!DOCTYPE html>
html>
head>
title>/title>
/head>
body>
?php
function poker(){
//建立數(shù)組保存牌組
$num = ['A','2','3','4','5','6','7','8','9','10','J','Q','K'];
$icon = ['♥'=>'red','♦️'=>'red','♠'=>'black','♣'=>'black'];
//生成撲克牌組
foreach ($icon as $key => $vi) {
foreach ($num as $vn) {
$poker[] = "font style ='color:$vi;'> $vn $key /font>";
}
}
$poker[] = "font style = 'color:red;'>大王/font>";
$poker[] = "font style = 'color:black;'>小王/font>";
shuffle($poker); // 亂序
return $poker;
}
?>
/body>
/html>
!DOCTYPE html>
html>
head>
title>撲克大賽/title>
style type="text/css">
div{margin: 15px 0;}
font{border: 1px solid #ccc;padding: 6px 3px; margin-right: 10px;}
/style>
/head>
body>
div>劉德華的牌/div>
?php
include './poker.php'; //調(diào)用
$sp = poker();
for ($i=1; $i =12 ; $i++) {
echo current($sp);
next($sp);
}
?>
div>周潤發(fā)的牌/div>
?php
for ($i=1; $i =12 ; $i++) {
echo current($sp);
next($sp);
}
?>
div>李飛揚的牌/div>
?php
for ($i=1; $i =12 ; $i++) {
echo current($sp);
next($sp);
}
?>
/body>
/html>