EVEN ODD Number In PHP

EVEN ODD Number is a formula of an integer value. Today I am going to discuss with you about how to use and create web application using EVEN ODD Number In PHP

What is EVEN Number?
EVEN number is an integer which is evenly divisible by two. If you divide the integer by two and if it has no remainder after divided then the number is EVEN number.

What is ODD Number?
ODD number is an integer which is not divisible by two. If you divide the integer then you will get a remainder. then the number is ODD number.

In this tutorial, I am going to show you about even odd in PHP. how to detect a number even or odd? you can detect a number even or odd using simple PHP math calculation. Let's see the calculation,

<?php
$number = 12;
switch ($number%2)
{
case 0:
echo 'EVEN Number';
break;
default:
echo 'ODD Number';
}
?>
// Ourput EVEN Number
EVEN ODD Number Result
and if you run this code, 

<?php
$number = 15;
switch ($number%2)
{
case 0:
echo 'EVEN Number';
break;
default:
echo 'ODD Number';
}
?>
Now it will execute, ODD Number.

Now we are going to make a game for kids using this function. create a file name index.php and write down this code into index.php file,

<?php
if (isset($_POST['start'])&&$_POST['start']==1)
{
$ans = $_POST['answer'];
$number = $_POST['number'];

switch ($number%2)
{
case 0:
$value = 2;
$correct ="EVEN Number";
break;
default:
$value = 1;
$correct ="ODD Number";
}
if($ans==$value)
{
echo 'You are correct! this is '.$correct;
}
else
{
echo 'You are wrong! this is '.$correct;
}
$number = rand(100,10000);
echo '<b>'.$number.'</b>';
echo '<br/><b>What is the number?</b><br/>';
echo '<form method="post">';
echo '<input type="radio" name="answer" value="1" required> ODD Number<br/>';
echo '<input type="radio" name="answer" value="2" required> EVEN Number<br/><br/>';
echo '<input type="hidden" name="start" value="1">';
echo '<input type="hidden" name="number" value="'.$number.'">';
echo '<input type="submit" value="Submit">';
echo '</form>';

?>
If you run this script then you will see a random number and two option EVEN number & ODD Number select any option and click to submit then you will show a result.
Even ODD Demo
I will upload this script into this article you can download and add a style of this script as you like.
If you have any question about this article please comment here and if you like this article please share this with others.

Download Source Code
Unlock source code with a social share.

Did you like this article? it will be appreciated if you share a coffee or burger with the author

Sent $5 to the author
Sent $10 to the author

Need Assistance?

I'm Sajjad Hossain, working on web application development since 2012. Do you need assistance on your project? or are you stuck with problems? I am available to help you.
If you want to contact with me ping me at -

WhatsApp
Skype


We use cookies on our website. To find out more about how and why they are used or opt-out, please read our Cookie Policy. By choosing "I Accept", you consent to our use of cookies. Cookie Policy
Top