note 103161 added to function.shuffle

From: Date: Tue, 29 Mar 2011 17:33:55 +0000
Subject: note 103161 added to function.shuffle
Groups: php.notes 
Request: Send a blank email to php-notes+get-178309@lists.php.net to get a copy of this message
Copy and paste this script and refresh the page to see the shuffling effect. <?php /** * Shuffles and displays cards in a deck * @author: Eric Anderson * @filename: deckofcards.php */ // Create an array of face values // and an array of card values // then merge them together $cards = array_merge(array("J", "Q", "K", "A"), range(2,10)); // 13 cards // Shuffle the cards shuffle($cards); // Create an multidimentional array to hold the 4 suits $suits = array( 'Heart' => array(), 'Spade' => array(), 'Diamond' => array(), 'Club' => array() ); // Add cards to their respective suits for($i = 0; $i < count($suits); $i++) { for($j = 0; $j < count($cards); $j++) { $suits['Heart'][$j] = $cards[$j]."<span style=color:#FF0000;>&hearts;</span>"; $suits['Spade'][$j] = $cards[$j]."&spades;"; $suits['Diamond'][$j] = $cards[$j]."<span style=color:#FF0000;>&diams;</span>"; $suits['Club'][$j] = $cards[$j]."&clubs;"; } } // Create a deck $deck = array(); // Merge the suits into the empty deck array $deck = array_merge($deck, $suits); // Display the deck to the screen echo "<p><b>Deck of cards:</b></p>"; foreach($deck as $k1 => $v1) { // Display suit name echo "<p>&emsp;$k1's<br />&emsp;{<br />&emsp;&emsp;"; $acc = 0; // Display card value foreach($v1 as $k2 => $v2) { echo "$v2&nbsp"; $acc++; if ($acc == 4) { echo "<br />&emsp;&emsp;"; $acc = 0; } } echo "<br />&emsp;}</p>"; } ---- Server IP: 64.71.164.2 Probable Submitter: 208.54.40.62 ---- Manual Page -- http://www.php.net/manual/en/function.shuffle.php Edit -- https://master.php.net/note/edit/103161 Del: integrated -- https://master.php.net/note/delete/103161/integrated Del: useless -- https://master.php.net/note/delete/103161/useless Del: bad code -- https://master.php.net/note/delete/103161/bad+code Del: spam -- https://master.php.net/note/delete/103161/spam Del: non-english -- https://master.php.net/note/delete/103161/non-english Del: in docs -- https://master.php.net/note/delete/103161/in+docs Del: other reasons-- https://master.php.net/note/delete/103161 Reject -- https://master.php.net/note/reject/103161 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178309) next »