That's a decent way to do it, however I feel it would be more generic, though a tad more programming to do it like this.
First define two arrays:
<?php
$cards = array('A','1','3','4','5','6','7','8','9','10','J','Q','K');
$suits = array('C','D','H','S');
?>
Then create a 13x4 matrix. The columns represent the cards you should give them names accordingly to make the code more readable. The rows represent the suits. This code does the trick
<?php
/*array*/ function buildEmptyDeck($cards,$suits) {
$retval = array();
foreach($cards as $card) {
$retval[$card] = array();
foreach($suits as $suit)
$retval[$card][$suit] = 0;
} //end foreach
return $retval;
} //end buildEmptyDeck
?>
Then you should generate some hands. This code does the trick, with no repeats
<?php
/*array*/ function buildHands($numHands,$numCards,$cards,$suits) {
$i = 1;
$cardLimit = count($cards)-1;
$suitLimit = count($suits) - 1;
$retval = array();
$temp = array();
mt_srand();
for($i=0;$i<$numHands;$i++) {
$j = 0;
$retval[$i] = array();
while($j < $numCards) {
$card = $cards[mt_rand(0,$cardLimit)] . ' ' .
$suits[mt_rand(0,$suitLimit)];
if(array_search($card,$temp) === FALSE) {
$temp[] = $card;
$retval[$i][] = $card;
$j++;
} //end if
} //end while
} //end for
return $retval;
} //end buildHands
?>
Now we need to "deal" these hands from the deck. We'll do this by placing markers into the deck array for each used card that signify whose hand the card is in. The code for this is pretty simple
<?php
/*void*/ function dealHands(&$deck,$hands) {
$i=1;
foreach($hands as $hand) {
foreach($hand as $card) {
$acard = explode(' ',$card);
$deck[$acard[0]][$acard[1]] = $i;
} //end foreach
$i++;
} //end foreach
} //end dealHands
?>
So let's recap what we have so far. In the first step we specified our available cards and suits. In the second step we created an empty deck and in the third step we created some hands. In the fourth step we "dealt" the hands out of the deck.
To explain why I have done things this way to this point. First of all defining the cards and suits dynamically makes it possible for you to decide that you're not playing with a standard deck of cards, which means this portion of the program could be used to deal the initial hands for any card game including uno, phase 10, weed, etc.
The next step will be writting the programming to pull the reward groups out of the deck array. I'll cover that in another post and this one is already getting very long and it's getting very late.