Posted By

andyhartleeds on 11/26/08


Tagged

numericnumberparityoddevenfunction


Versions (?)

Number Parity function (checking if a number is odd or even)


 / Published in: PHP
 

  1. if ($i&1) {
  2. 3.
  3. {
  4. 4.
  5. echo "$i is odd";
  6. 5.
  7. }
  8. 6.
  9. else
  10. 7.
  11. {
  12. 8.
  13. echo "$i is even";
  14. 9.
  15. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ginoplusio on November 26, 2008

if($i % 2 ==0) {odd} else {even}

Posted By: Scooter on December 21, 2008

echo ($i % 2 == 0) ? "odd" : "even";

What do I win?

You need to login to post a comment.