Variable name which has the smallest value among 3 numeric variables

I have 3 numeric variables. I like to find which one is the smallest one.

I made the code below for finding the variable name which has the smallest value.

[code]if($number1 < $number2 ) {

$smaller=$number1; $smallerName=‘number1’;

} else { $smaller=$number2; $smallerName=‘number2’;}

if($number3 < $smaller) {

echo $smallerName;[/code]The code above works fine. but I think more simple code there in the outside.
Do you have any?

do you really need the name of the variable? this may cause messy code (e.g. variable variables)

$min = min($num1, $num2, $num3);

Stick them in an array and use the index number instead of worrying about the name?

you can make use of arrays to declare the variables

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.