codrgii Posted July 4, 2010 Share Posted July 4, 2010 How do i detect in PHP if an result if odd or even? like for example if($result == 1 || $result == 3 || $result == 5) {//ODD NUMBER } ELSE {//EVEN NUMBER } How do i do something like above without manually searching for odd numbers? Link to comment https://forums.phpfreaks.com/topic/206704-odd-even-numbers-in-php/ Share on other sites More sharing options...
Alex Posted July 4, 2010 Share Posted July 4, 2010 Check to see if when divided by 2 there is a remainder, using the modulus operator. if($num % 2 == 0) { // even } else { // odd } Link to comment https://forums.phpfreaks.com/topic/206704-odd-even-numbers-in-php/#findComment-1081026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.