Find Greatest Number from 10 inputs : PHP Assignment

I used input bar code in this assignment, which my teacher gave me to use. I used 10 input bars with different names. Then I used while loop and if conditional statement within loop to make this assignment successful.
Note : Try this code : Download Find Greatest Number Script


 <?PHP  
      $inputs = array();  
      if (isset($_POST['submit'])) { //to check if the form was submitted  
           $value = isset($_POST['input0'])? $_POST['input0'] : null;  
           for($count = 1; $value != null; $count++){  
                array_push($inputs, $value);  
                $value = isset($_POST['input'.$count])? $_POST['input'.$count] : null;  
           }  
      }  
      var_dump($inputs);  
 ?>       
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
   <!-- to take multiple inputs copy the below line and change name="input" attribute -->  
   Enter input 1:&nbsp;<input type="text" name="input0" value="" /><br />  
   Enter input 2:&nbsp;<input type="text" name="input1" value="" /><br />  
   Enter input 3:&nbsp;<input type="text" name="input2" value="" /><br />  
   Enter input 4:&nbsp;<input type="text" name="input3" value="" /><br />  
   Enter input 5:&nbsp;<input type="text" name="input4" value="" /><br />  
   Enter input 6:&nbsp;<input type="text" name="input5" value="" /><br />  
   Enter input 7:&nbsp;<input type="text" name="input6" value="" /><br />  
   Enter input 8:&nbsp;<input type="text" name="input7" value="" /><br />  
   Enter input 9:&nbsp;<input type="text" name="input8" value="" /><br />  
   Enter input 10:&nbsp;<input type="text" name="input9" value="" /><br />  
   <input type="submit" name="submit" value="Submit" />  
 </form>  
 <?php  
     $max = $inputs[0]; //this variable to store values to array  
     $count = 1; //this variable to run the loop 10 times  
     while ($count < 10) //here it is Terminate condition  
     {  
         if ($max < $inputs[$count])  
         {  
           $max = $inputs[$count];  
         }  
       $count++;  
     }  
     echo "$max is greatest <br/>";  
 ?>  

Post a Comment

Give your reviews about this blog. Leave your comments. What do you think about this post?

Comments Guidelines:

1) I love to read comments, but please avoid spam.

2) Like this blog, share your insights, and spread the word.

3) You can use basic HTML/xHTML tags.

4) All comments are DoFollow—please use the section professionally.

5) Kindly mention your name or brand below your comment.

6) Constructive suggestions for improvement are always welcome.


Thanks for visiting Samee Articles.

========================================

Best Regards,

Samee U. Feroz

 
Copyright © 2011-2026. Samee Articles - All Rights Reserved
Proudly powered by Blogger