even and odd
Moderator: General Moderators
even and odd
Is there a php function to tell if a number is even or odd?
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Code: Select all
<?php
if($num%2==0)
echo "even";
else
echo "odd";
?>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;Real programmers don't comment their code. If it was hard to write, it should be hard to understand.