Jump to content


Photo

even number detecting?


  • Please log in to reply
2 replies to this topic

#1 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 15 October 2006 - 08:08 PM

Hi, i need some way to be able to detect whether a number is even or not. I searched the php manual but couldn't find anything that does this.

Anyone know of a way to do this?

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 15 October 2006 - 08:13 PM

modulus operator - http://ca.php.net/operators.arithmetic

<?php
$num = 4; // example
if ($num%2) {
    echo "odd";
} else {
    echo "even";
}
?>

Legend has it that reading the manual never killed anyone.
My site

#3 Tandem

Tandem
  • Members
  • PipPipPip
  • Advanced Member
  • 251 posts

Posted 15 October 2006 - 08:18 PM

Thanks, i'll give this a try.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users