Helping ordinary people create extraordinary websites!
   

Can anyone write a php code for greatest of three nos using if else?

Wednesday, 9th September 2009
by chakku2k88


I need the code to determine the greatest of three numbers using if statements. I would like for the input to be entered via the user.





bbrainz
Hello there,

You can try the below code:

<?php

$a = 240;
$b = 520;
$c = 322;

$max ='';

if($a > $b)
$max = $a;
else
$max = $b;

if($max < $c)
echo "Greatest number is: $c";
else
echo "Greatest number is: $max";

?>


Thanks.
Tuesday, 15th September 2009
Votes:
28
12

phpdreams
That would work for three numbers, but what if you have 20? I would put the values into an array then do an arsort() on the array. Then the first entry in the array would be the biggest.

You can also checkout the link below for a comparison of array sorting functions.

Sources:

Friday, 9th October 2009
Votes:
13
13

More PHP Help:
» I would like to create a profit / loss php scipt, any ideas?
» What is PHP?
» Where should I go to learn PHP?
» How to write a code for timing the user when the user start typing in the text box?
» How to get the ID of the last record inserted into MySQL database?
» PHP file to script
» How to check server report after each 5 minutes
» How to upload file in PHP?