robert_gsfame Posted May 15, 2010 Share Posted May 15, 2010 i have this simple code <?php $i=0; $tot=0; while($i==1){ $rand=rand(0,9); while($mynumber=array(5,6)){ if(in_array($rand,$mynumber)){ $tot++;} } if($tot==0){ $i++;}else{} } echo $rand; ?> how can $rand always come up with number other than 2 numbers in array. This code give me blank result...which part is actually wrong thx Link to comment https://forums.phpfreaks.com/topic/201864-simple-loop-problem/ Share on other sites More sharing options...
kenrbnsn Posted May 15, 2010 Share Posted May 15, 2010 What are you trying to accomplish here? You're loop isn't executing because you initialize $i to zero and then say <?php while($i==1) ?> Ken Link to comment https://forums.phpfreaks.com/topic/201864-simple-loop-problem/#findComment-1058748 Share on other sites More sharing options...
robert_gsfame Posted May 15, 2010 Author Share Posted May 15, 2010 i want to have number as a result of echo $rand but other than numbers in array so i wish to have random number between 0-9 minus numbers in array Link to comment https://forums.phpfreaks.com/topic/201864-simple-loop-problem/#findComment-1058751 Share on other sites More sharing options...
kenrbnsn Posted May 15, 2010 Share Posted May 15, 2010 Try <?php $mynumber = array(5,6); $rand = rand(0,9); while (in_array($rand,$mynumber)) { $rand = rand(0,9); } echo $rand; ?> Ken Link to comment https://forums.phpfreaks.com/topic/201864-simple-loop-problem/#findComment-1058757 Share on other sites More sharing options...
robert_gsfame Posted May 15, 2010 Author Share Posted May 15, 2010 thx for your help!! Link to comment https://forums.phpfreaks.com/topic/201864-simple-loop-problem/#findComment-1058759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.