Murchu Posted February 20, 2013 Share Posted February 20, 2013 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 ☺ Quote Link to comment https://forums.phpfreaks.com/topic/274750-create-associative-array-of-deck-of-cards/ Share on other sites More sharing options...
requinix Posted February 20, 2013 Share Posted February 20, 2013 (edited) 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", ... ); Edited February 20, 2013 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/274750-create-associative-array-of-deck-of-cards/#findComment-1413748 Share on other sites More sharing options...
Barand Posted February 20, 2013 Share Posted February 20, 2013 $colour = array_keys($suits, $suit) % 2 ? 'red' : 'black'; Quote Link to comment https://forums.phpfreaks.com/topic/274750-create-associative-array-of-deck-of-cards/#findComment-1413751 Share on other sites More sharing options...
wiggy Posted February 21, 2013 Share Posted February 21, 2013 Oh come on dont be so lazy do Derek's work yourself. You know he'd go mad if he knew what you are up to!!! Quote Link to comment https://forums.phpfreaks.com/topic/274750-create-associative-array-of-deck-of-cards/#findComment-1414005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.