Skip to main content

How To Check Highest And Lowest Numbers In PHP


In this tutorial, we are going to learn on How To Check Highest And Lowest Numbers In PHP.

You can create this simple program using PHP Language. This program can determine the highest number and the lowest number after the user input a given value on the box. Then, click the enter button to show the result. Hope you find this useful.

HTML Form

This is the HTML form that the user input six value to the box.

  1. <h2>Highest and Lowest Number Checker in PHP</h2>
  2.  
  3. <form class="form_style" action="" method="post">
  4. <label>Value Number 1 : </label>
  5. <input type="number" class="text_style" name="value_no1" value="<?php echo $a_1; ?>" size="5" maxlength="5" autofocus="autofocus" />
  6. <br/><br>
  7. <label>Value Number 2 : </label>
  8. <input type="number" class="text_style" name="value_no2" value="<?php echo $b_1; ?>" size="5" maxlength="5"/>
  9. <br/><br>
  10. <label>Value Number 3 : </label>
  11. <input type="number" class="text_style" name="value_no3" value="<?php echo $c_1; ?>" size="5" maxlength="5"/>
  12. <br/><br>
  13. <label>Value Number 4 : </label>
  14. <input type="number" class="text_style" name="value_no4" value="<?php echo $d_1; ?>"size="5" maxlength="5"/>
  15. <br/><br>
  16. <label>Value Number 5 : </label>
  17. <input type="number" class="text_style" name="value_no5" value="<?php echo $e_1; ?>"size="5" maxlength="5"/>
  18. <br/><br />
  19. <label>Value Number 6 : </label>
  20. <input type="number" class="text_style" name="value_no6" value="<?php echo $f_1; ?>"size="5" maxlength="5"/>
  21.  
  22. <br />
  23. <br/>
  24. <br />
  25.  
  26. <input type="submit" class="btn_style1" value="Enter" name="enter" />
  27. <input type="submit" class="btn_style2" value="Reset" name="reset" />
  28. </form>

PHP Function

This is a PHP code determine the highest and lowest number by clicking the enter button.

  1. <?php
  2. if(isset($_POST['enter']))
  3. {
  4. $six_valueAll = array($a_1,$b_1,$c_1,$d_1,$e_1,$f_1);
  5.  
  6. $max_number =$six_valueAll[0];
  7. $min_number = $six_valueAll[0];
  8.  
  9. foreach($six_valueAll as $key => $valueChoose){
  10. if($min_number > $valueChoose){
  11. $min_number = $valueChoose;
  12. }
  13. if($max_number < $valueChoose){
  14. $max_number = $valueChoose;
  15. }
  16. }
  17.  
  18. $highest_number = "<b style='color:blue;'>The Highest Number is " .$max_number."</b>.<br>";
  19. $lowest_number = "<b style='color:red;'>The Lowest Number is " .$min_number." </b>.";
  20.  
  21. echo "<br><br>";
  22. echo "<div style='margin-top:-260px; margin-right:250px; float:right;'>";
  23. echo "<b>".$highest_number."</b>"."<br>";
  24. echo "<b>".$lowest_number."</b>";
  25. echo "</div>";
  26. }
  27. ?>

And, this PHP code for the reset button, to have a new entry value of numbers in the box.

  1. <?php
  2. $a_1= $_POST['value_no1'];
  3. $b_1= $_POST['value_no2'];
  4. $c_1= $_POST['value_no3'];
  5. $d_1= $_POST['value_no4'];
  6. $e_1= $_POST['value_no5'];
  7. $f_1= $_POST['value_no6'];
  8. if(isset($_POST['reset']))
  9. {
  10. $a_1=""; $b_1=""; $c_1=""; $d_1=""; $e_1=""; $f_1="";
  11. $highest_number=""; $lowest_number="";
  12. }
  13. ?>

CSS

Also, this is our CSS style.

  1. <style type="text/css">
  2. .form_style {
  3. width: 300px;
  4. }
  5. label {
  6. float: left;
  7. width: 150px;
  8. color:blue;
  9. font-size:18px;
  10. }
  11. h2 {
  12. color:red;
  13. }
  14. .text_style {
  15. font-size:18px;
  16. width:100px;
  17. border:red 1px solid;
  18. text-align:center;
  19. color:red;
  20. }
  21. .btn_style1 {
  22. font-size:18px;
  23. color:red;
  24. background:azure;
  25. border:skyblue 1px solid;
  26. padding:5px;
  27. width:100px;
  28. margin-right:100px;
  29. float:left;
  30. }
  31. .btn_style2 {
  32. font-size:18px;
  33. color:blue;
  34. background:white;
  35. border:red 1px solid;
  36. padding:5px;
  37. width:100px;
  38. }
  39. </style>

Share us your thoughts and comments below. Thank you so much for dropping by and reading this blog post. For more updates, don’t hesitate and feel free to visit our website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.