Hi Folks,
The following code is developing and echoing a poker hand. The code is sorting the hand by suit. Is there a straightforward way to sort the hand, instead, by rank of card?
The finished product is at http://www.marainlaw.com/page.php?here=quotationsCode:$suits = array( "♠", "<span style='color : #ff4040; '>♥</span>", "<span style='color : #ff4040; '>♦</span>", "♣" ); $ranks = array ( "Ace", "Deuce", "Trey", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "king" ); $card = 0; // loop index: We'll draw five cards $cardsInSuit = 13; // number of cards for each suit, ace low $deck = range (0, 51); // establishes array of numbers from 0 to 51 shuffle ($deck); // and this shuffles the "deck" $raw_hand = array_slice ($deck, 0, 5); // extract first five cards sort ($raw_hand); // sort echo "<div align='right'><font size='-1'>Here is your " . $handStatus . "poker hand. Please use it wisely:<br />"; while ($card < 5) { // will iterate for $card = 0, 1, 2, 3, 4 $lemma = $raw_hand[$card]; // select "card" from raw hand, call it $lemma $rank = $lemma % $cardsInSuit; // place it in range of zero to twelve $pips = $ranks[$rank]; // find spelled out rank of card, from ranks array $lemma = floor($lemma / $cardsInSuit); // determine quartile (52 divided by 13 = 4) $suit = $suits[$lemma]; // select suit corresponding to quartile echo "$pips $suit "; // echo processed card to screen $card ++; // bump card count }



Reply With Quote
Bookmarks