Skip to content

Instantly share code, notes, and snippets.

@jayd3e
Created July 25, 2014 20:52
Show Gist options
  • Save jayd3e/b1383500f258bce5a15e to your computer and use it in GitHub Desktop.
Save jayd3e/b1383500f258bce5a15e to your computer and use it in GitHub Desktop.
<?php
$suits = array('C', 'D', 'H', 'S');
$cards = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K','A');
$deck = array();
foreach ($suits as $suit) {
foreach ($cards as $card) {
array_push($deck, $suit . $card);
}
}
$deck = shuffle_the_array($deck);
echo print_r($deck);
function shuffle_the_array($array) {
$i = count($array);
while(--$i) {
$j = mt_rand(0, $i);
if ($i != $j) {
$tmp = $array[$j];
$array[$j] = $array[$i];
$array[$i] = $tmp;
}
}
return $array;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment