VB icon

Highest and Lowest Number Checker in PHP

Email
Submitted on: 1/17/2016 4:22:41 AM
By: Jake R. Pomperada  
Level: Beginner
User Rating: By 1 Users
Compatibility: PHP 3.0, PHP 4.0, PHP 5.0
Views: 3267
author picture
 
     A simple program that I wrote in PHP that will determine the highest and lowest number from the given six numbers given by the user. I don't use any built in function in PHP like max() and min() to check for highest and lowest number. I hope you will find my work useful in your learning PHP programming. If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Highest and Lowest Number Checker in PHP
// Description:A simple program that I wrote in PHP that will determine the highest and lowest number from the given six numbers given by the user. I don't use any built in function in PHP like max() and min() to check for highest and lowest number. I hope you will find my work useful in your learning PHP programming.
If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
// By: Jake R. Pomperada
//**************************************

<?php
error_reporting(0);
$a= $_POST['val_1'];
$b= $_POST['val_2'];
$c= $_POST['val_3'];
$d= $_POST['val_4'];
$e= $_POST['val_5']; 
$f= $_POST['val_6']; 
 if(isset($_POST['clear']))
{ 
$a=""; $b=""; $c=""; $d=""; $e=""; $f="";
$highest_number=""; $lowest_number="";
}
?>
<html>
<head>
<title>Highest and Lowest Number Checker in PHP</title>
<style>
body { font-family:arial;}
form { width: 400px; }
label { float: left; width: 120px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }
</style>
</head>
<body>
<h2>Highest and Lowest Number Checker in PHP</h2>
<form action="" method="post">
<label>Item Number 1 : </label> <input type="text" name="val_1" value="<?php echo $a; ?>" size="5" maxlength="5" autofocus/><br/><br>
<label>Item Number 2 : </label> <input type="text" name="val_2" value="<?php echo $b; ?>" size="5" maxlength="5"/><br/><br>
<label>Item Number 3 : </label> <input type="text" name="val_3" value="<?php echo $c; ?>" size="5" maxlength="5"/><br/><br>
<label>Item Number 4 : </label> <input type="text" name="val_4" value="<?php echo $d; ?>"size="5" maxlength="5"/><br/><br>
<label>Item Number 5 : </label> <input type="text" name="val_5" value="<?php echo $e; ?>"size="5" maxlength="5"/><br/><br />
<label>Item Number 6 : </label> <input type="text" name="val_6" value="<?php echo $f; ?>"size="5" maxlength="5"/><br/><br />
<input type="submit" value="Ok" name="check" title="Click here to check for the highest and lowest number."/>
   
<input type="submit" value="Clear" name="clear" title="Click here to clear the text box." />
</form>
<?php
if(isset($_POST['check']))
{ 
 $arr = array($a,$b,$c,$d,$e,$f);
 
 $max =$arr[0];
 $min = $arr[0];
 
foreach($arr as $key => $val){
if($min > $val){
$min = $val;
}
 if($max < $val){
$max = $val;
}
}		
 
 $highest_number = "The Highest Number is " .$max.".<br>";
 $lowest_number = "The Lowest Number is " .$min.".";
 
 echo "<br><br>";
 echo "<b>".$highest_number."</b>"."<br>";
 echo "<b>".$lowest_number."</b>";
}
?>
</body>
</html>


Other 46 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.