frost Posted August 27, 2007 Share Posted August 27, 2007 In the following: if($var%2) Does the % stand for "divisible by"? I ask because I tried if($var%3) and got some wacky stuff... Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/66902-solved-percent-sign/ Share on other sites More sharing options...
trq Posted August 27, 2007 Share Posted August 27, 2007 It is the modulus operator. In your first example, it will return the remainder of $var divided by 2. Quote Link to comment https://forums.phpfreaks.com/topic/66902-solved-percent-sign/#findComment-335378 Share on other sites More sharing options...
effigy Posted August 27, 2007 Share Posted August 27, 2007 In other words, if ($var is an odd number). Quote Link to comment https://forums.phpfreaks.com/topic/66902-solved-percent-sign/#findComment-335384 Share on other sites More sharing options...
frost Posted August 27, 2007 Author Share Posted August 27, 2007 Ah, that makes sense. So if I wanted to see if $var was divisible by 3 how would I do that? Quote Link to comment https://forums.phpfreaks.com/topic/66902-solved-percent-sign/#findComment-335434 Share on other sites More sharing options...
wildteen88 Posted August 27, 2007 Share Posted August 27, 2007 If you want to see if something is divisible by three use the following: if($var%3 == 0) { } Quote Link to comment https://forums.phpfreaks.com/topic/66902-solved-percent-sign/#findComment-335442 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.