note 86017 modified in function.max by danbrown
| From: | danbrown@php.net | Date: | Mon, 29 Sep 2008 16:52:18 +0000 |
| Subject: | note 86017 modified in function.max by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-144879@lists.php.net to get a copy of this message | ||
This code loops through seven arrays and finds the highest average value within those arrays - and
changes the font color for it. Great for highlighting.
The biggest take-away is this the row
if($average[$i] == max($average))
The number_format just rounds the numbers to 0 decimal points.
<?php
for ( $i = 0; $i <= 6; $i++) {
$num = $i+1;
if($average[$i] == max($average)) {
echo "Value ".$num.": <font
color='red'>".number_format($average[$i], 0, '.', '')." %
</font<br>";
} else {
echo "Value ".$num.":
".number_format($average[$i],0,'.','')." %<br>";
}
}
?>
### OUTPUT
Value 1: 52 %
Value 2: 58 %
Value 3: 56 %
Value 4: 73 %
Value 5: 77 % <- this 77 is highlighted in red
Value 6: 71 %
Value 7: 75 %
--was--
This code loops through seven arrays and finds the highest average value within those arrays - and
changes the font color for it. Great for highlighting.
The biggest take-away is this the row
if($average[$i] == max($average))
The number_format just rounds the numbers to 0 decimal points.
for ( $i = 0; $i <= 6; $i++) {
$num = $i+1;
if($average[$i] == max($average))
echo "Value ".$num.": <font
color='red'>".number_format($average[$i], 0, '.', '')." %
</font><br>";
else echo "Value ".$num.": ".number_format($average[$i], 0, '.',
'')." %<br>";
}
### OUTPUT
Value 1: 52 %
Value 2: 58 %
Value 3: 56 %
Value 4: 73 %
Value 5: 77 % <- this 77 is highlighted in red
Value 6: 71 %
Value 7: 75 %
http://php.net/manual/en/function.max.php