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.
<?php
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
- Remove edit, view, trash and quick edit links within posts list of admin screen - WordPress
- PHP Errors not displaying or not logging - LAMP server - Solved
- Display all hooks sequentialy that run on a page - WordPress
- Get downloadable files of a downloadable product - WooCoomerce
- Add actions based on WooCoomerce order status
Your Questions / Comments
If you found this article interesting, found errors, or just want to discuss about them, please get in touch.