homepage Welcome to WebmasterWorld Guest from 54.226.10.234
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
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

10+ Year Member



 
Msg#: 11688 posted 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

10+ Year Member



 
Msg#: 11688 posted 12:06 am on Feb 10, 2006 (gmt 0)

[us2.php.net...]

dkin

10+ Year Member



 
Msg#: 11688 posted 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

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 11688 posted 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

10+ Year Member



 
Msg#: 11688 posted 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.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved