Jump to content

Comparing variables


esiason14

Recommended Posts

I have a series of variables that need to be compared against eachother.

 

For example...

$ab = 3;

$bab = 4;

$cab = 5;

 

These will be displayed in a table...Whichever variable has the highest value will be highlighted.

 

How can I compare these without using a gazillion if statements

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/53029-comparing-variables/
Share on other sites

<?php
/**
* if you put the variables into an array instead of separate vars
*
*/

        $arr =  array();
        $arr[] = 3;
        $arr[] = 4;
        $arr[] = 5;

        $max = max($arr);


foreach ($arr as $val) {
    if ($val==$max)
        echo "<span style='font-weight:600; color:#F00'>$val</span><br>";
    else
        echo "$val<br>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/53029-comparing-variables/#findComment-262013
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.