shamuraq Posted September 13, 2009 Share Posted September 13, 2009 can't seem to get this to work... $num = rand(1,9); do{ $num1digit1 = rand(1,9); }while($num1digit1 = $num); echo $num1digit1; Any sugestions? Quote Link to comment https://forums.phpfreaks.com/topic/174053-solved-do-while-function-help/ Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 i never used a do while in php... but i think this is the same $num = rand(1,9); $num1digit1 = rand(1,9); while($num1digit1 != $num){ $num1digit1 = rand(1,9); } echo $num1digit1; not sure the point of it is though Quote Link to comment https://forums.phpfreaks.com/topic/174053-solved-do-while-function-help/#findComment-917462 Share on other sites More sharing options...
shamuraq Posted September 13, 2009 Author Share Posted September 13, 2009 the reason i use the loop is to prevent both the variables from having the same value... Quote Link to comment https://forums.phpfreaks.com/topic/174053-solved-do-while-function-help/#findComment-917463 Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 the reason i use the loop is to prevent both the variables from having the same value... ah ok then... $num = rand(1,9); $num1digit1 = rand(1,9); while($num1digit1 == $num){ $num1digit1 = rand(1,9); } echo $num1digit1; Quote Link to comment https://forums.phpfreaks.com/topic/174053-solved-do-while-function-help/#findComment-917466 Share on other sites More sharing options...
shamuraq Posted September 13, 2009 Author Share Posted September 13, 2009 actually i'd just like to take this opportunity to clarify this what is the difference between: $num1digit1 == $num; and $num1digit1 = $num; when i tried the second one, there are times it doesn't work... Quote Link to comment https://forums.phpfreaks.com/topic/174053-solved-do-while-function-help/#findComment-917471 Share on other sites More sharing options...
l0ve2hat3 Posted September 13, 2009 Share Posted September 13, 2009 == is an operator... asking if something is equal to something = is defining the variable Quote Link to comment https://forums.phpfreaks.com/topic/174053-solved-do-while-function-help/#findComment-917478 Share on other sites More sharing options...
ngreenwood6 Posted September 13, 2009 Share Posted September 13, 2009 Just to clarify a little bit further: == comparison operator (compare a value) = assignment operator (assign a value) The code that he gave you should work ALL the time Quote Link to comment https://forums.phpfreaks.com/topic/174053-solved-do-while-function-help/#findComment-917482 Share on other sites More sharing options...
shamuraq Posted September 13, 2009 Author Share Posted September 13, 2009 thanx y'all Quote Link to comment https://forums.phpfreaks.com/topic/174053-solved-do-while-function-help/#findComment-917499 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.