Return to Snippet

Revision: 3961
at March 23, 2010 10:38 by andyhartleeds


Updated Code
// Change '10' to be any number you want
<?=(10&1) ? "odd" : "even"?>

Revision: 3960
at October 9, 2007 09:31 by andyhartleeds


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

Initial URL


Initial Description
How to check if a number is odd or even in PHP. Could also use the MOD (%) function, but apparently this method is better performance-wise.

Initial Title
How to check if a number is odd or even

Initial Tags
php, number

Initial Language
PHP