PHP实现随机发扑克牌


<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>

// 建立数组保存的牌组池
    $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[] = " {$value} {$iconkey}";
        }
    }
    shuffle($poker);   //打乱数组
?>
head>
<body>
<div>玩家A 牌组div>
 for ($i = 0; $i < 10; ++$i) {
    echo current($poker);
    next($poker);
} ?>
<div>玩家B 牌组div>
 for ($i = 0; $i < 10; ++$i) {
    echo current($poker);
    next($poker);
} ?>
<div>玩家C 牌组div>
 for ($i = 0; $i < 10; ++$i) {
    echo current($poker);
    next($poker);
} ?>
body>
html>

PHP实现随机发扑克牌_第1张图片

你可能感兴趣的:(PHP)