4.22.3. Discussion
Here, a pair of arrays, $suits and
$cards, is created to hold the English
representation of a card. The numbers 0 through
51 are randomly arranged and assigned to
$deck. To deal a card, just pop them off the top
of the array, treating the array like a literal deck of cards.
It's necessary to add the check against
NULL inside the while,
otherwise the loop terminates when you draw the zeroth card. If you
modify the deck to contain the numbers 1 through 52, the mathematics
of deciding which number belongs to which card becomes more complex.
To deal multiple cards at once, call array_slice(
):
array_slice($deck, $cards * -1);