MemphiS Posted June 2, 2007 Share Posted June 2, 2007 What i have is a card deck below... And i need it not to pick a card that is already picked. <?php $fdeck = array("2-H","3-H","4-H","5-H","6-H","7-H","8-H","9-H","10-H","11-H","12-H","13-H","14-H", "2-D","3-D","4-D","5-D","6-D","7-D","8-D","9-D","10-D","11-D","12-D","13-D","14-D", "2-S","3-S","4-S","5-S","6-S","7-S","8-S","9-S","10-S","11-S","12-S","13-S","14-S", "2-C","3-C","4-C","5-C","6-C","7-C","8-C","9-C","10-C","11-C","12-C","13-C","14-C"); $drawedDeck = array("0"); ////////////////////////////// // DEALERS DECK // for ($t=0; $t<52; $t++){ shuffle($fdeck); $countCRD = count($fdeck); $yourcaRD = rand()%$countCRD; if ($fdeck[$yourcaRD]==""){ $t--; }else{ if (in_array($yourcaRD, $drawedDeck)){ $yourcaRD = rand()%$countCRD; } array_push($yourcaRD, $drawedDeck); $mYcrd[] = $fdeck[$yourcaRD]; $fdeck[$yourcaRD]==""; } } That was my attempt which it doesnt work :s Someone have a solution? ?> Quote Link to comment https://forums.phpfreaks.com/topic/53986-producing-random-cards/ Share on other sites More sharing options...
chigley Posted June 2, 2007 Share Posted June 2, 2007 <?php $deck = array("2-H","3-H","4-H","5-H","6-H","7-H","8-H","9-H","10-H","11-H","12-H","13-H","14-H", "2-D","3-D","4-D","5-D","6-D","7-D","8-D","9-D","10-D","11-D","12-D","13-D","14-D", "2-S","3-S","4-S","5-S","6-S","7-S","8-S","9-S","10-S","11-S","12-S","13-S","14-S", "2-C","3-C","4-C","5-C","6-C","7-C","8-C","9-C","10-C","11-C","12-C","13-C","14-C"); $chosendeck = array(); shuffle($deck); for ($i = 0; $i <= 51; $i++) { if(!in_array($deck[$i], $chosendeck)) { $chosendeck[] = $deck[$i]; } else { $i--; } } echo "<pre>".print_r($chosendeck, true)."</pre>"; ?> Sorry for any typos, laptop is in function key mode and can't disable it! Quote Link to comment https://forums.phpfreaks.com/topic/53986-producing-random-cards/#findComment-266872 Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 how bout this? <?php $fdeck = array("2-H","3-H","4-H","5-H","6-H","7-H","8-H","9-H","10-H","11-H","12-H","13-H","14-H","2-D","3-D","4-D","5-D","6-D","7-D","8-D","9-D","10-D","11-D","12-D","13-D","14-D","2-S","3-S","4-S","5-S","6-S","7-S","8-S","9-S","10-S","11-S","12-S","13-S","14-S","2-C","3-C","4-C","5-C","6-C","7-C","8-C","9-C","10-C","11-C","12-C","13-C","14-C"); $drawn=array(); for($i=0; $i<=4; $i++){ $new=$fdeck[array_rand($fdeck)]; if(!in_array($new,$drawn)) $drawn[]=$new; else $i--; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53986-producing-random-cards/#findComment-266873 Share on other sites More sharing options...
MemphiS Posted June 2, 2007 Author Share Posted June 2, 2007 Thank you chigley and taith got it working now Quote Link to comment https://forums.phpfreaks.com/topic/53986-producing-random-cards/#findComment-266900 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.