I'm working on a "card game" in which cards are randomly dealt from all four suites to up to 4 players. I created two separate arrays, one for the 13 cards, and one for the 4 suites. Below is the code I have for just 1 player.
Arrays:
<?php
$suite=array("Clubs", "Diamonds", "Hearts", "Spades");
$random_suite=array_rand($suite, 4);
?>
<?php
$card=array("Ace", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King");
$random_card=array_rand($card,5);
?>
If Statements (Don't believe a problem exists here):
<?php if (!is_numeric($_GET['players']))
{
echo "You did not enter a value for Number of Players; click the 'Return'
button and enter a number.";
}
elseif ($_GET['players'] < 1)
{
echo "You entered a number less than 1 which is the minimum allowed; click
the 'Return' button to enter another number.";
}
elseif ($_GET['players'] > 4)
{
echo "You entered a number greater than 4 which is the maximum allowed; click
the 'Return' button to enter another number.";
}
else {
echo "<br>Dealing up Cards for 4 players
<br>Hand for Player Number 1:
Combining Arrays:
<br>{$card[$random_card[0]]} of {$suite[$random_suite[0]]}
<br>{$card[$random_card[1]]} of {$suite[$random_suite[1]]}
<br>{$card[$random_card[2]]} of {$suite[$random_suite[2]]}
<br>{$card[$random_card[3]]} of {$suite[$random_suite[3]]}
<br>{$card[$random_card[4]]} of {$suite[$random_suite[4]]}";
}
?>
Using
<?php
$suite=array("Clubs", "Diamonds", "Hearts", "Spades");
$random_suite=array_rand($suite, 4);
?>
gives me this, which makes sense from the number being 4. However, if I change this to 5 which is how many cards need to be dealt, I get this, probably because there's only 4 suites.
So, what's wrong with my code?
Bonus: I also need to figure out how to make all cards that are dealt unique. I can't have two ace of spades. If someone could help me with this as well, I'd be grateful.