Posted By

andyhartleeds on 10/09/07


Tagged

php number is a checking odd even if or


Versions (?)

Who likes this?

20 people have marked this snippet as a favorite

gedittest
vali29
hudge
heinz1959
axthos
Hollow
ktstone
HereticSun
ira
philokezzar
joethermal
brainwaves
bobbym245
mecha
codyg
divtagged
ljayz
Net-Freak
jhonqwerty
ringo380


How to check if a number is odd or even


 / Published in: PHP
 

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.

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

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: axthos on October 9, 2008

I LOVE THIS CODE OH SO MUCH

Posted By: andyhartleeds on March 10, 2010

Thanks! =)

Posted By: andyhartleeds on March 23, 2010

Cheers! :)

You could technically do the following as well, which is even shorter:

...replacing '10' with your own number. :)

Posted By: andyhartleeds on March 23, 2010

...sorry, that didn't post! :-\

Instead I've added a new shorter version of the script. :)

You need to login to post a comment.