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! Link to comment https://forums.phpfreaks.com/topic/191971-check-if-i-is-multiple-of-10/ 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. Link to comment https://forums.phpfreaks.com/topic/191971-check-if-i-is-multiple-of-10/#findComment-1011817 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"; } Link to comment https://forums.phpfreaks.com/topic/191971-check-if-i-is-multiple-of-10/#findComment-1011819 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.