homepage Welcome to WebmasterWorld Guest from 50.19.33.5
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Finding the greater value
dkin




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

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

 

Nutter




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

[us2.php.net...]

dkin




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

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

Thanks

Dijkgraaf




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

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.

Nutter




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved