A freelance web developer living in Montreal who spends most of his time writing for this site and building Premium themes for WordPress. You can find him on Twitter @bavotasan.
I have been doing it the long way around before this. My code was around 3 times as long as this!
Premium Themes for WordPress
Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com. You can even get a Premium theme for FREE by signing up with Site5 hosting!
If you're interested in writing an article or tutorial please drop me a line and let me know. I'm currently looking to hire some freelance writers to help contribute to bavotasan.com.
If you would like to support c.bavota and bavotasan.com, please use the donate link below. Any amount, even $1.00, is appreciated (a man's gotta eat, ya know).
How about:
print ($a % 2 ? 'even' : 'odd');
Btw: first line should be <?php otherwise you get an error
s/b
print ($a % 2 == 0 ? ‘even’ : ‘odd’);
if ($num % 2 == 0 )
echo “even”;
else
echo “odd”;
And here is a function:
function is_odd($n){
return (boolean) ($n % 2);
}
You can also create the is_even() function when you understand the concept.
WOW! Thx for the “function”. Pretty easy and clear for me.
Hey pretty cool! thx verry much!!
Nice little php code. Could be good for a random function.
return (boolean) ($n % 2);
is better than the other codes because it will return 0 or 1 which can be cast into a boolean value where 0 = true and 1 = false.
I have been doing it the long way around before this. My code was around 3 times as long as this!