PHP實現隨機發撲克牌
阿新 • • 發佈:2020-04-24
本文例項為大家分享了PHP實現隨機發撲克牌的具體程式碼,供大家參考,具體內容如下
<!doctype html> <html> <!-- 隨機發撲克牌 --> <head> <meta charset="UTF-8"> <title>隨機發牌</title> <style> div{margin:15px 0} font{border:1px solid #ccc;padding:6px 3px;margin-right:10px} </style> <?php // 建立陣列儲存的牌組池 $num = ['A','2','3','4','5','6','7','8','9','10','J','Q','K']; $icon = ['♥' => 'red','♦' => 'red','♠' => 'black','♣' => 'black']; //生成撲克牌 $poker = []; foreach ($icon as $iconkey => $iconvalue) { foreach ($num as $value) { $poker[] = "<font style='color:$iconvalue'> {$value} {$iconkey}</font>"; } } shuffle($poker); //打亂陣列 ?> </head> <body> <div>玩家A 牌組</div> <?php for ($i = 0; $i < 10; ++$i) { echo current($poker); next($poker); } ?> <div>玩家B 牌組</div> <?php for ($i = 0; $i < 10; ++$i) { echo current($poker); next($poker); } ?> <div>玩家C 牌組</div> <?php for ($i = 0; $i < 10; ++$i) { echo current($poker); next($poker); } ?> </body> </html>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。