Sunday, November 29, 2015

High and Low Number Checker in PHP

This sample program that I wrote in PHP will check for the highest and lowest number from the five number given by the user using one dimensional array in PHP. Take note I did not use any built in function in PHP like Max and Min function to determine the highest and lowest number. I hope you will find my work useful in learning how to program in PHP.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output

Program Listing

<?php
error_reporting(0);
    
    
    $a = $_POST["numbers"][0];
    $b = $_POST["numbers"][1];
    $c = $_POST["numbers"][2];
    $d = $_POST["numbers"][3];
    $e = $_POST["numbers"][4];

if  ($_POST['send']) 
  {

      $list=array($a,$b,$c,$d,$e);

    $highest_number=0;
    
    $lowest_number=0;

    $high=0;
    
    $low=0;
    
    // checking for highest number
    
 $highest_number = $list[0];
    
    foreach($list as $high)
    {
      if ($highest_number < $high)
      {
        $highest_number = $high;
      } 
    }
                 
// checking for lowest number

$lowest_number = $list[0];

  foreach($list as $low)
      {
        if ($lowest_number > $low)
        {
          $lowest_number = $low;
        } 
     }
 }   


 if ($_POST['clear'])
   {
   $a=""; $b=""; $c=""; $d=""; $e="";
   $highest_number="";
   $lowest_number="";  
  }

?>
<html>
 <style>
 body {
  font-family:arial;
  font-size:12;
  }
</style>   
<title> Highest and Lowest Number Checker</title>
<form action = "" method = "POST">
<body>
<h3> Highest and Lowest Number Checker </h3>
<table border = "0">
<tr>
   <td> 1st Value </td>
   <td> <input type = "text" name ="numbers[]" value = "<?php echo $a;?>" size="5" autofocus required>
   </tr>
   <tr>
   <td> 2nd Value </td>
   <td> <input type = "text" name ="numbers[]"  value = "<?php echo $b;?>" size="5"  required>
   </tr>
   <tr>
   <td> 3rd Value </td>
   <td> <input type = "text" name ="numbers[]"  value = "<?php echo $c;?>" size="5" required>
   </tr>
   <tr>
   <td> 4th Value </td>
   <td> <input type = "text" name ="numbers[]"  value = "<?php echo $d;?>" size="5" required >
   </tr>
   <tr>
   <td> 5th Value </td>
   <td> <input type = "text" name ="numbers[]"  value = "<?php echo $e;?>" size="5" required>
   </tr>
   <tr>
   <td> &nbsp;</td>
   </tr>
   <tr>
   <tr>
   <td> <b> Highest Number </b> </td>
   <td> <input type = "text"  value = "<?php echo $highest_number;?>" size="5" readonly>
   </tr>
   <tr>
   <td> &nbsp;</td>
   </tr>
   <tr>
   <td> <b>Lowest Number </b> </td>
   <td> <input type = "text"  value = "<?php echo $lowest_number;?>" size="5" readonly>
   </tr>
   <tr>
   <td> &nbsp;</td>
   </tr>
   <tr>
   <td colspan = 3>
        <input type = "submit" name="send" value = "OK" title="Click here to check highest and lowest number.">
        &nbsp;&nbsp;
        <input type = "submit" name="clear" value = "Clear" title="Click here to clear text boxes.">
   </td>
   </tr>
   </table>
   </form>
  </body>
 </html>


No comments:

Post a Comment