Jump to content

Create Associative array of deck of cards?


Murchu

Recommended Posts

Hi All

 

I wish to create an Associative array of a deck of cards,

 

the user $_GET's from radio buttons a sequences of 3 colors, red, red, black for example.

 

the program also picks a sequences of colors

 

while there are cards in the deck , i wish to write a program that records which sequence

 

is encountered the most, and out put the winner by how much ??

 

 

$suits = array ( "Spades", "Hearts", "Clubs", "Diamonds");

 

$cards = array ("2", "3", "4", "5", "6", "7", "8","9", "10", "Jack", "Queen", "King", "Ace");

 

$deck = array();

 

foreach ($suits as $suit)

{

foreach ($cards as $card)

{

$deck[ ] = array ("Card" => $card, "Suit" => $suit);

}

}

 

how should i continue and how to attach colors to this array ??

 

Thanks for any advice offered ☺

Associate the suits with their colors. You could

$suits = array ( array ( "Spades", "black" ), array ( "Hearts", "red" ), ... );

or

$suits = array ( "black" => array ( "Spades", "Clubs "), ... );

or

$suits = array ( "Spades" => "black", "Hearts" => "red", ... );

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.