esiason14 Posted May 26, 2007 Share Posted May 26, 2007 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 More sharing options...
neel_basu Posted May 26, 2007 Share Posted May 26, 2007 Single = sign is to assign values you need to use == Sign to compare values Link to comment https://forums.phpfreaks.com/topic/53029-comparing-variables/#findComment-261963 Share on other sites More sharing options...
Barand Posted May 26, 2007 Share Posted May 26, 2007 <?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 More sharing options...
esiason14 Posted May 26, 2007 Author Share Posted May 26, 2007 Thanks! That worked...much appreciated Link to comment https://forums.phpfreaks.com/topic/53029-comparing-variables/#findComment-262119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.