Without using Modulus Find Even and Odd in PHP for loop

Even & Odd using for loop without Modulus
In this small tutorial we are going to demonstrate a code in php using for loop and finding Even & Odd numbers without using Modulus. So lets check the code :
What was the use of Modulus in PHP ?
Modulus ( % ) is designed to find remainder , in our previous ChessBoard Tutorial using For Loop we used Modulus to find Odd and Even to print a chessboard type layers. Here in this tutorial we are not going to use Modulus but another thing called is_int() , this is_int() is a inbuilt function of PHP to find if a number is integer or not. And we know if a number divided by 2 gives whole number means its a Even number and if it comes in fraction means its Odd number. In PHP fraction number means Float and Whole number means Integer.
So lets check our PHP code to find Even Odd without using Modulus.
<?php $a = 15; for($k=1; $k <= $a; $k++) { if(is_int($k/2)) { echo $k.' is even'; echo '<br />'; } else { echo $k.'is odd'; echo '<br />'; } } ?>
This is so simple , right ? all we are check every number if it will get divided by 2 gives integer or float. That’s it.
Do you like more PHP Tutorials ?