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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.