Monday, 2 February 2015

Check if number is Odd or Even

Check if number is Odd or Even

Here we have a simple function that returns TRUE or FALSE when checking if an INT is odd or even.


<?php
/**
* number to check
*/
$num 3;
/**
*
* @Check if number is odd or even
*
* @var $num The number to check
*
* Return BOOL
*
*/
function checkNum($num){
  return (
$num%2) ? TRUE FALSE;
}

if(
checkNum($num) === TRUE){
  echo 
'its odd';
}else{
  echo 
'its even';
}  ?>

0 comments:

Post a Comment