Welcome to WebmasterWorld Guest from 54.166.87.123

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Finding the greater value

   
12:01 am on Feb 10, 2006 (gmt 0)

10+ Year Member



I have 3 variables I would like to check the value of each and select the one that is the highest. They must be atleast .05 or higher

I was thinking something like

if ($var1 <= .049 ¦¦ $var2 <= .049 ¦¦ $var3 <= .049 )
{

echo 'value to low';

}
else
{
this is where Im confused, how to select the variable with the highest value

}

any help is appreciated.

Thanks

Turk

12:06 am on Feb 10, 2006 (gmt 0)
12:08 am on Feb 10, 2006 (gmt 0)

10+ Year Member



sweet, your the man, hope your a man, or else your the woman :D * digging digging digging* shutting up :)

Thanks

12:12 am on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



If all you want is the value, then the below would do the trick.

if ($var1 <= .049 $var2 <= .049 $var3 <= .049 )
{

echo( 'value too low');

}
else
{
$highest= $var1;
if ($var2 > $highest) $highest=$var2;
if ($var3 > $highest) $highest=$var3;
echo('highest value is $highest';

}

P.S. Haven't actually tried it in PHP so may have syntax errors.

Putting a loop in like the example the URL has, makes it more flexible as well.

2:19 pm on Feb 10, 2006 (gmt 0)

10+ Year Member



You can stop digging, you got it right the first time :-)

If it were me...

$max_val = max($var1, $var2, $var3);
if ($max_val<0.05)
{
echo "Value too low";
}
else
{
// Do whatever you need to with the value
}

That way you save the ORs and it would be easier to add more variabes later if you need to.