PHP Scripting

Greatest Number

learn php by example for find the greatest number

5/19/2020
0 views
php-greatest-number.phpPHP
<!DOCTYPE html>
<html>
	<head>
		<title>Greatest Number</title>
	</head>
	<body>

		/* "$_SERVER['PHP_SELF']" get the current URL of the file */
		<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
			<input type="text" name="fst_no" placeholder="First Number" />
			<input type="text" name="snd_no" placeholder="Second Number" />
			<input type="submit" />
		</form>
		<?php

			/* 'isset()' check the variable exists or not */
			if(isset($_POST['fst_no']) && isset($_POST['snd_no'])) {

				/* 'is_numeric()' check the variable contain number or not */
				if(is_numeric($_POST['fst_no']) && is_numeric($_POST['snd_no'])) {

					/* Compare two numbers */
					if($_POST['fst_no'] > $_POST['snd_no']) 
						echo $_POST['fst_no']." is Greatest Number!";
					else
						echo $_POST['snd_no']." is Greatest Number!";
				}
				else
					echo "Not a valid number!";
			}
		?>
	</body>
</html>




/* Output */
Input:
fst_no = 7
snd_no = 4

7 is the Greatest Number!

/* ---------------------------------------------- */

Input:
fst_no = ab
snd_no = cd

Not a valid number!
PHPgreatest numberphp tutorialHypertext Preprocessor

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com