PHP - Simple Highest And Lowest Number Checker
Submitted by razormist on Sunday, April 21, 2019 - 22:17.
In this tutorial we will create a Simple Highest And Lowest Number Checker using PHP. This code can identify whether the given number is the highest or the lowest. The code use an array to enclose the data inputs to be able to get a specific number by using a conditional statement. This is a user-friendly kind of program feel free to modify it.
We will be using PHP as a scripting language and interpreter that is used primarily on any webserver including xamp, wamp, etc. It is being use to any famous websites and it has a modern technology that can easily be use by the next generation.
There you have it we successfully created Simple Highest And Lowest Number Checker using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!
Getting Started:
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html. And, this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into your text editor, then save it as index.php.- <?php
- $digit1= $_POST['digit1'];
- $digit2= $_POST['digit2'];
- $digit3= $_POST['digit3'];
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
- </head>
- <body>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a>
- </div>
- </nav>
- <div class="col-md-3"></div>
- <div class="col-md-6 well">
- <h3 class="text-primary">PHP - Simple Highest And Lowest Number Checker</h3>
- <hr style="border-top:1px dotted #ccc;"/>
- <div class="col-md-2"></div>
- <div class="col-md-8">
- <form action="" method="post">
- <div class="form-group">
- <label>Digit 1 : </label>
- <input type="number" class="form-control" name="digit1" value="<?php echo $digit1; ?>" min="0" required="required"/>
- </div>
- <div class="form-group">
- <label>Digit 2 : </label>
- <input type="number" class="form-control" name="digit2" value="<?php echo $digit2; ?>" min="0" required="required"/>
- </div>
- <div class="form-group">
- <label>Digit 3 : </label>
- <input type="number" class="form-control" name="digit3" value="<?php echo $digit3; ?>" min="0" required="required"/>
- </div>
- <center><button class="btn btn-primary" name="get">Get number</button> <a href="index.php" class="btn btn-success" name="reset">Reset</a></center>
- <br /><br />
- <?php include 'check.php'?>
- </form>
- </div>
- </div>
- </body>
- </html>
Creating the Main Function
This code contains the main function of the application. This code will get a specific number when the button is clicked. To make this just copy and write these block of codes below inside the text editor, then save it as check.php- <?php
- $highest =$array[0];
- $lowest = $array[0];
- foreach($array as $key => $value){
- if($lowest > $value){
- $lowest = $value;
- }
- if($highest < $value){
- $highest = $value;
- }
- }
- echo "<center><label style='font-size:20px;'>The highest number is <span class='text-primary' style='font-size:25px;'>".$highest."</span></label></center>";
- echo "<center><label style='font-size:20px;'>The lowest number is <span class='text-danger' style='font-size:25px;'>".$lowest."</span></label></center>";
- }
- ?>
Add new comment
- 178 views