Powered by InterCreatives | Site Map
Search:
NewSourceMedia Popular Tutorials: PHP Javascripts Web Hosting
SoftwareTutorials
CATEGORIES
Job Listings
 
Home / PHP / Math

PHP how to find Odd and Even numbers


How to find if a number is odd or even?
In PHP I learn to use the MOD (%) operator. see below for an example: $i = 10;

if ($i % 2) {
echo "$i is odd";
} else {
echo "$i is even";
}

You can also use the PHP "&" operator that will give you better performance
You can use the PHP code like so:

$i = 10;
if ( $i&1 )
{
echo "$i is odd";
}
else
{
echo "$i is even";
}


Next PHP Page:
1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  [26]  27  28  29  30  31  32 





Hosting by iPowerWeb.com - 50 Gb for $7.95