EchoFool Posted August 24, 2009 Share Posted August 24, 2009 Hey I'm having difficulties with my shuffle array function, its meant to shuffle the array then return it, and then when i echo position 0 in the array i get the value returned "1". Even thought its not in the array.. which is confusing... Heres my script: Function <?php function shuffledeck() { $cards = array('DA','D2','D3','D4','D5','D6','D7','D8','D9','D10','DJ','DQ','DK', 'HA','H2','H3','H4','H5','H6','H7','H8','H8','H19','HJ','HQ','HK', 'CA','C2','C3','C4','C5','C6','C7','C8','C9','C10','CJ','CQ','CK', 'SA','S2','S3','S4','S5','S6','S7','S8','S9','S10','SJ','SQ','SK'); $Deck = shuffle($cards); return array($Deck); } ?> On a php script: <?php $Deck = shuffledeck(); Echo $Deck[0]; ?> The Echo just displays 1 Where am i going wrong here? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 24, 2009 Share Posted August 24, 2009 At some point, either before, during, and especially after what you are attempting does not work, you need to read the documentation for what you are doing. shuffle() does not return an array it shuffles the array it is given as a parameter - Description bool shuffle ( array &$array ) This function shuffles (randomizes the order of the elements in) an array. Parameters array The array. Return Values Returns TRUE on success or FALSE on failure. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted August 24, 2009 Author Share Posted August 24, 2009 Argh i worked out a method now need two functions for it ! Quote Link to comment 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.