fork download
  1. <?php
  2.  
  3. function is_even($num) {
  4. return is_int($num) && abs($num % 2) == 0;
  5. }
  6. function is_odd($num) {
  7. return is_int($num) && abs($num % 2) == 1;
  8. }
  9. // this last one seems self-explanatory, but if you want it, here it is
  10. function is_neither_even_nor_odd($num) {
  11. return !is_even($num) && !is_odd($num);
  12. }
  13.  
  14. // Tests: The following should all output true:
  15. is_even(0),
  16. is_even(2),
  17. is_even(-6),
  18. is_even(51238238),
  19. is_odd(1),
  20. is_odd(-1),
  21. is_odd(57),
  22. is_neither_even_nor_odd(1.5),
  23. is_neither_even_nor_odd(2.5),
  24. is_neither_even_nor_odd(-0.5),
  25. is_neither_even_nor_odd(0.00000001)
  26. );
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)