Created
July 25, 2014 20:52
-
-
Save jayd3e/b1383500f258bce5a15e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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