---
title: "Greatest Number"
description: "learn php by example for find the greatest number"
url: "https://www.geekboots.com/php/greatest-number"
markdown_url: "https://www.geekboots.com/php/greatest-number/md"
category: "PHP Scripting"
author: "Geekboots"
published: "2016-06-06"
updated: "2026-11-11T11:49:21.794Z"
tags: ["PHP", "greatest number", "php tutorial", "Hypertext Preprocessor"]
---

# Greatest Number (PHP Scripting)

> learn php by example for find the greatest number

## Source Code

### php-greatest-number.php

```php
<!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!
```

## Related Code Examples

- [Fetch MySQL Data](https://www.geekboots.com/php/fetch-mysql-data) ([Markdown](https://www.geekboots.com/php/fetch-mysql-data/md))
- [Imagick](https://www.geekboots.com/php/imagick) ([Markdown](https://www.geekboots.com/php/imagick/md))
- [Read XML File](https://www.geekboots.com/php/read-xml-file) ([Markdown](https://www.geekboots.com/php/read-xml-file/md))
- [Create XML File](https://www.geekboots.com/php/create-xml-file) ([Markdown](https://www.geekboots.com/php/create-xml-file/md))
- [Read CSV file](https://www.geekboots.com/php/read-csv) ([Markdown](https://www.geekboots.com/php/read-csv/md))
- [Read File](https://www.geekboots.com/php/read-file) ([Markdown](https://www.geekboots.com/php/read-file/md))
- [Copy File](https://www.geekboots.com/php/copy-file) ([Markdown](https://www.geekboots.com/php/copy-file/md))
- [Create Delete File](https://www.geekboots.com/php/create-delete-file) ([Markdown](https://www.geekboots.com/php/create-delete-file/md))

---
Source: [Geekboots](https://www.geekboots.com/php/greatest-number)
