I have a session issue
$types = array("diamonds","hearts","spades","clubs");
$cards = array("Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King");
$possible_cards = array();
foreach($types AS $type)
{
foreach($cards AS $card)
{
$possible_cards[] = strtolower($card).':of:'.$type;
}
}
I have this code to generate card names such as "8:of:diamonds" and such, this works fine
this is the print_r result of $possible_cards array
Array ( [0] => ace:of:diamonds [1] => 2:of:diamonds [2] => 3:of:diamonds [3] => 4:of:diamonds [4] => 5:of:diamonds [5] => 6:of:diamonds [6] => 7:of:diamonds [7] => 8:of:diamonds [8] => 9:of:diamonds [9] => 10:of:diamonds [10] => jack:of:diamonds [11] => queen:of:diamonds [12] => king:of:diamonds [13] => ace:of:hearts [14] => 2:of:hearts [15] => 3:of:hearts [16] => 4:of:hearts [17] => 5:of:hearts [18] => 6:of:hearts [19] => 7:of:hearts [20] => 8:of:hearts [21] => 9:of:hearts [22] => 10:of:hearts [23] => jack:of:hearts [24] => queen:of:hearts [25] => king:of:hearts [26] => ace:of:spades [27] => 2:of:spades [28] => 3:of:spades [29] => 4:of:spades [30] => 5:of:spades [31] => 6:of:spades [32] => 7:of:spades [33] => 8:of:spades [34] => 9:of:spades [35] => 10:of:spades [36] => jack:of:spades [37] => queen:of:spades [38] => king:of:spades [39] => ace:of:clubs [40] => 2:of:clubs [41] => 3:of:clubs [42] => 4:of:clubs [43] => 5:of:clubs [44] => 6:of:clubs [45] => 7:of:clubs [46] => 8:of:clubs [47] => 9:of:clubs [48] => 10:of:clubs [49] => jack:of:clubs [50] => queen:of:clubs [51] => king:of:clubs )
I make a loop statement to add random card names into sessions
for($i=1;$i<=6;$i++)
{
$rand = rand(0,sizeof($possible_cards));
$_SESSION['blackjack_your_card_'.$i] = $possible_cards[$rand];
unset($possible_cards[$rand]);
$rand = rand(0,sizeof($possible_cards));
$_SESSION['blackjack_dealer_card_'.$i] = $possible_cards[$rand];
unset($possible_cards[$rand]);
}
this is where the problem lies, some of the session variables such as $_SESSION['blackjack_dealer_card_3'] will be filled in as blank instead of "9:of:clubs" or whatever
Could anyone help me find the source of this problem?