Page 1 of 1

even and odd

Posted: Thu Jul 08, 2004 12:50 pm
by mattmcb
Is there a php function to tell if a number is even or odd?

Posted: Thu Jul 08, 2004 12:52 pm
by magicrobotmonkey

Code: Select all

<?php
if($num%2==0)
  echo "even";
else
   echo "odd";

?>

Posted: Thu Jul 08, 2004 3:30 pm
by pickle
Or even [Edit: "even" as in "even this will work", not odd/even.... ah forget it]

Code: Select all

$even_or_odd = ($num%2 == 0) ? "even" : "odd";
echo $even_or_odd;