Sebolains Posted December 8, 2007 Share Posted December 8, 2007 Hi. I was wondering if there is a function, or a simple way to do an IF to check wether a variable is odd or even. Ex.: If ($num is even) { lalalala } . Is there a way? Thanks for everyone. Quote Link to comment https://forums.phpfreaks.com/topic/80775-solved-way-to-check-if-a-variable-is-odd-or-even/ Share on other sites More sharing options...
Henaro Posted December 8, 2007 Share Posted December 8, 2007 $n = 2; if($n%2 == 0){ echo "even"; }else{ echo "odd"; } Quote Link to comment https://forums.phpfreaks.com/topic/80775-solved-way-to-check-if-a-variable-is-odd-or-even/#findComment-409692 Share on other sites More sharing options...
Sebolains Posted December 8, 2007 Author Share Posted December 8, 2007 thanks Quote Link to comment https://forums.phpfreaks.com/topic/80775-solved-way-to-check-if-a-variable-is-odd-or-even/#findComment-409701 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.