24. PHP Program to Check if a number is Positive or Negative.
How does this program work?
- In this program you are going to learn about to check if a number is positive or negative using PHP.
- This problem is solved using if and nested if...else statement.
- A number is positive if it is greater than zero. We check this in the expression of if.
- If it is False, the number will negative.
Here is the code
<html>
<head>
<title>PHP Program To check a given number is positive or negative</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" name="num" value="" placeholder="Enter a number"/>
</td>
</tr>
<tr>
<td> <input type="submit" name="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit']))
{
$number = $_POST['num'];
//If number is greater than zero then it prints postive number else it prints negative number
if($number >= 0)
{
echo " $number is a positive number ";
}
else
{
echo " $number is a negative number ";
}
return 0;
}
?>
</body>
</html>