PHP code to find the largest of 3 numbers

Explanation of the code


This program finds the largest of three numbers. The three text boxes named t1, t2 and t3 is used to read the numbers. The php code will execute only if the submit button is clicked, this is achieved by using the statement if(isset($_POST["submit"])). When the submit button is clicked, the values entered in the text boxes will be stored in the variables n1, n2 and n3 respectively. Then the program will find the largest of these three numbers using if else condition check.

PHP code


<html>
<head>
<title>GREATEST OF THREE NUMBERS</title>
</head>
<body>
<font size=5>LARGEST OF THREE NUMBERS</font>
<br/>
<br/>
<form action="largest.php" method="post">
ENTER FIRST NUMBER:<input type="text" name="t1">
<br><br>
ENTER SECOND NUMBER:<input type="text" name="t2">
<br><br>
ENTER THIRD NUMBER:<input type="text" name="t3">
<br><br>
<input type="submit" value="CHECK" name="submit">
<?php
if(isset($_POST["submit"]))
{
$n1=$_POST["t1"];
$n2=$_POST["t2"];
$n3=$_POST["t3"];
if($n1>$n2)
{
if($n1>$n3)
echo "$n1 is greater";
else
echo "$n3 is greater";
}
else if($n2>$n3)
{
if($n2>$n1)
{
echo "$n2 is greater";
}
else
{
echo "$n3 is greater";
}}}
?>
</form>
</body>
</html>

Output




Largest of three numbers in PHP
Largest of three numbers in PHP