你得到重复牌的原因是因为你没有检查牌组合是否已经被处理过。
最好的解决方案是建立一组卡片并使用它来检查是否已创建卡片组合。然后回显构建的数组。
<?php
//The user input
$input = $_POST["txtNumberOfCards"];
$suit = array( "Hearts" , "Diamonds" , "Clubs" , "Spades" );
$card = array( "Ace" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" , "Jack" , "Queen" , "King");
//$dealArray holds the cards as they are dealt and used to compare what cards have all ready been dealt
$dealArray= array( );
//$count the while loop counter variable
$count = 0;
//while the $count variable is less then the $input
while( $count < $input )
{
//generate a card combination array
$cardCombo = array( 'suit' => $suit[ rand( 0 , 3 ) ],//Generate Random suit
'card' => $card[ rand( 0 , 12 ) ] );//Generate Random card
//if the $cardCombo array that was generated is not in the $dealArray
if ( !in_array( $cardCombo , $dealArray ) )
{
//Add the $cardCombo array to the end of the $dealArray
array_push( $dealArray , $cardCombo );
//Output an HTML image for the $cardCombo array
echo ( '<img src="Images/' . $cardCombo['card'] . 'of' . $cardCombo['suit'] . '.gif">' );
$count++;//Add 1 to the counter
}
}
?>