<?php //define number $num = 31; //see if number is odd or even //result: "Number is odd" echo (1&$num) ? "Number is odd" : "Number is even";↵ ?>
For the odd numbers, it expressed in binary format and the least significant digit is always 1, whereas for even numbers, it is always 0. If you don't fully understand the listing above, you can take a look at http://www.gamedev.net/reference/articles/article1563.asp for a tutorial on bitwise manipulation. More than that, you can consider a different test which involves dividing the number by 2 and checking the number alternatively (with the even numbers, the remainder will be zero). Beneath, this alternative is illustrated as follows:
<?php //define number $num = 10; //see if number mod 2 returns a remainder //result: "Number is even" echo ($num % 2) ? "Number is odd" : "Number is even"; ?>