bozebo Posted October 20, 2007 Share Posted October 20, 2007 Ok, I have a card game I'm working on, its all fine except the sudden death setting, where the 2 player's cards (10 cards in total) are merged and shuffled then dished out (so, 2 arrays of 5 numbers) here is the part that is causing problems: $cards_host_start = array(1,2,3,4,5); $cards_client_start = array(6,7,8,9,10); $mixed_cards = array_merge($cards_host_start,$cards_client_start); $mixed_cards = shuffle($mixed_cards); for($cardindex = 0;$cardindex <= 4;$cardindex++){ $hostcards_sudden[$cardindex] = $mixed_cards[$cardindex]; } $hostcards_sudden = implode(',',$hostcards_sudden); for($cardindex = 5;$cardindex <= 9;$cardindex++){ $clientcards_sudden[$cardindex] = $mixed_cards[$cardindex]; } $clientcards_sudden = implode(',',$clientcards_sudden); echo $hostcards_sudden .'<br />'. $clientcards_sudden; I have stuck it into a test page: http://www.bozebo.com/mixtest/ OK, with that, both arrays are full of null values, so its imploded as just ,,,,. when I remove the line: $mixed_cards = shuffle($mixed_cards); the output is the same as the input, which i would expect, because the arrays are just merged then split laboriously. so.. why isn't shuffle working correctly? Quote Link to comment https://forums.phpfreaks.com/topic/74123-solved-not-solvedshuffle-command-not-working/ Share on other sites More sharing options...
darkfreaks Posted October 20, 2007 Share Posted October 20, 2007 <?php $mixedcards = shuffle($mixedcards);?> http://us2.php.net/manual/en/function.shuffle.php Quote Link to comment https://forums.phpfreaks.com/topic/74123-solved-not-solvedshuffle-command-not-working/#findComment-374291 Share on other sites More sharing options...
bozebo Posted October 20, 2007 Author Share Posted October 20, 2007 <?php $mixedcards = shuffle($mixedcards);?> ehm.. what? thanks for giving me a useless reply, now nobody will help because it has replies... Quote Link to comment https://forums.phpfreaks.com/topic/74123-solved-not-solvedshuffle-command-not-working/#findComment-374297 Share on other sites More sharing options...
steve448 Posted October 20, 2007 Share Posted October 20, 2007 <?php $mixedcards = shuffle($mixedcards);?> ehm.. what? thanks for giving me a useless reply, now nobody will help because it has replies... Was just reading this and thought having never used shuffle() before that I couldn't see why it doesn't work. So I followed darkfreaks link, and the answer is there for you. Although I did have to scroll down the page to the user notes to find it. Hint: This in fact does not work because shuffle returns a boolean true or false. More accurate code using this method would be: Quote Link to comment https://forums.phpfreaks.com/topic/74123-solved-not-solvedshuffle-command-not-working/#findComment-374322 Share on other sites More sharing options...
bozebo Posted October 20, 2007 Author Share Posted October 20, 2007 <?php $mixedcards = shuffle($mixedcards);?> ehm.. what? thanks for giving me a useless reply, now nobody will help because it has replies... Was just reading this and thought having never used shuffle() before that I couldn't see why it doesn't work. So I followed darkfreaks link, and the answer is there for you. Although I did have to scroll down the page to the user notes to find it. Hint: This in fact does not work because shuffle returns a boolean true or false. More accurate code using this method would be: oh? ill take a look edit: OH.. I was dumb to not notice that lol. Thanks.. (but darkfreaks' reply wasnt actually any help caus he thought the same thing as me ) OH lol.. now i have [sOLVED][not solved!].. ah well Quote Link to comment https://forums.phpfreaks.com/topic/74123-solved-not-solvedshuffle-command-not-working/#findComment-374337 Share on other sites More sharing options...
MadTechie Posted October 20, 2007 Share Posted October 20, 2007 So much a for a useless post.. maybe darkfreaks should of just said RTFM.. Quote Link to comment https://forums.phpfreaks.com/topic/74123-solved-not-solvedshuffle-command-not-working/#findComment-374341 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.