Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/myscript/public_html/codes-snippets/config.php on line 6
Odd or Even Number - Php

Odd or Even Number - Php

How to check if a number is odd or even using Php code?

Snippet Code


  
Rate this page :
  [ 0 votes]

This php code is used to check if number is odd or even. Here, modulo of a number is found. If output is 0, it is even number else, odd number.

<?php function odd_even($number) { if(($number % 2) == 0){ return true; } else{ return false; } } $result = odd_even(7); if($result=='true') { echo "Given number is Even";; } else{ echo "Given number is Odd"; } ?>

Tags


Ask Questions

Ask Question