0

我是 PHP/HTML 新手,我希望在单击按钮时显示一组卡片中的随机卡片。

到目前为止我有这段代码,但是我真的不知道我做错了什么。我能得到一些帮助吗?谢谢。

<form action="cards.php" method="get">
<input type=submit value="submit" name=draw>
</form>
<?php
$s=$_GET["draw"];
if ($s=="true")
{

    $cards[0]="1C";
    $cards[1]="2C";
    $cards[2]="3C";
    $cards[3]="4C";
    $cards[4]="5C";
    $cards[5]="6C";
    $cards[6]="7C";
    $cards[7]="8C";
    $cards[8]="9C";
    $cards[9]="10C";
    $cards[10]="AC";
    $cards[11]="KC";
    $cards[12]="QC";
    $cards[13]="JC";
    $cards[14]="1D";
    $cards[15]="2D";
    $cards[16]="3D";
    $cards[17]="4D";
    $cards[18]="5D";
    $cards[19]="6D";
    $cards[20]="7D";
    $cards[21]="8D";
    $cards[22]="9D";
    $cards[23]="10D";
    $cards[24]="AD";
    $cards[25]="KD";
    $cards[26]="QD";
    $cards[27]="JD";
    $cards[28]="1H";
    $cards[28]="2H";
    $cards[29]="3H";
    $cards[30]="4H";
    $cards[31]="5H";
    $cards[32]="6H";
    $cards[33]="7H";
    $cards[34]="8H";
    $cards[35]="9H";
    $cards[36]="10H";
    $cards[37]="AH";
    $cards[38]="KH";
    $cards[39]="QH";
    $cards[40]="JH";
    $cards[41]="1S";
    $cards[42]="2S";
    $cards[43]="3S";
    $cards[44]="4S";
    $cards[45]="5S";
    $cards[46]="6S";
    $cards[47]="7S";
    $cards[48]="8S";
    $cards[49]="9S";
    $cards[50]="10S";
    $cards[51]="AS";
    $cards[52]="KS";
    $cards[53]="QS";
    $cards[54]="JS";

    srand($cards);

    echo (rand (0-54));

}
?>
4

2 回答 2

1

在您的 php 中,只需执行

shuffle($cards);
echo $cards[0];
于 2012-11-28T18:21:23.773 回答
1

您应该使用以下array_rand功能:

$values = array_rand($input, 1);

笔记:

您可以像这样更快、更干净地创建一个数组:

$array = array(
     "a",
     "b",
     "c",
     "d",
);
于 2012-11-28T18:21:42.543 回答