Associative Arrays
Posted: Sun Sep 25, 2011 5:49 am
Hi need some help on the code
I can put data into the associate array but I cannot print the value with foreach ($dealer as $dc=> $dcv){echo "The Dealer card is :" . $dc ($dcv) . "<br>";}
Any help for a dummy would be appreciated.
I can put data into the associate array but I cannot print the value with foreach ($dealer as $dc=> $dcv){echo "The Dealer card is :" . $dc ($dcv) . "<br>";}
Any help for a dummy would be appreciated.
Code: Select all
<?php
$suits = array ("Spades", "Hearts", "Clubs", "Diamonds");
$faces = array ("Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace");
$deck = array();
foreach ($suits as $suit) {
foreach ($faces as $face) {$deck[] = array ("face"=>$face, "suit"=>$suit);}
}
shuffle($deck);
$dealer = array();
$card = array_shift($deck);
array_push ($dealer, $card);
$card = array_shift($deck);
array_push ($dealer, $card);
foreach ($dealer as $dc=> $dcv){echo "The Dealer card is :" . $dc ($dcv) . "<br>";}
?>