PHP program to check if a given number is ODD or EVEN

PHP Program to check number is odd or even


In this tutorial, you will learn how to check Odd or Even Number in PHP.

Below is the php script to find the given number is odd or even.

<html>
<head>
    <title>ODD or EVEN</title>
</head>
<body>

    <h2>PHP script to find given number is ODD or EVEN </h2>

    <form action="" method="post">
        <input type="text" name="num" />
        <input type="submit" />
    </form>

    <?php
        if($_POST)
        {
            $num = $_POST['num'];

            if(!is_numeric($num))
            {
                echo "String not allowed.
                Input should number";
                return;
            }
            if($num % 2==0)
            { 
                echo "Number is an even number";
            }
            else
            {
                echo "Number is an odd number ";
            }
        }
    ?>

</body>
</html>


Thanks for reading.

© Copyright - 2018 - 2022 | All rights reserved at Funda of Web IT