Check a number is even or odd in PHP

Today, I want to check weather a number is even or odd in my PHP appliation.

We can simply use an if else statement for this pourpose.

if($num % 2)
 echo 'Odd number';
} else{
 echo 'Even number';

If you like shortcodes in your program, we can write it in a single line.

<?php print ($i % 2 == 0 ? Even number : Odd number); ?>

Recent Posts

  1. Replace string in multiple files - Command line
  2. Solve Grunt error - Port 35729 is already in use by another process
  3. Install WP-CLI
  4. Install LAMP - Apache2 , MariaDB, PHP 7 on Debian 8
  5. Enable / Disable Magento 2 module using command line

Questions / Comments

If you found this article interesting, found errors, or just want to discuss about them, please get in touch. Send an email to & I like your words.