Vivid Lust Posted February 13, 2010 Share Posted February 13, 2010 Hi all, How can i check if $i, and integer, is a multiple of 10. E.g: INPUT 10 OUTPUT true INPUT 2000 OUTPUT true INPUT 170 OUTPUT true INPUT 295 OUTPUT false Thanks all! Quote Link to comment Share on other sites More sharing options...
premiso Posted February 13, 2010 Share Posted February 13, 2010 Use the modulus operator (%) if (($i % 10) == 0) { echo "$i is a multiple of 10<br />"; } Basically checks if $i / 10 has a remainder, if it does it is not a multiple of the number you are checking it against. Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 13, 2010 Share Posted February 13, 2010 Use the modulus operator: http://php.net/language.operators.arithmetic if ($i % 10 == 0) { echo "true"; } Quote Link to comment 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.