even and odd
Posted: Thu Jul 08, 2004 12:50 pm
Is there a php function to tell if a number is even or odd?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
if($num%2==0)
echo "even";
else
echo "odd";
?>Code: Select all
$even_or_odd = ($num%2 == 0) ? "even" : "odd";
echo $even_or_odd;