Hi Guys
Please help me
Suppose I have an array()
I want to find out the $colour with the highest value.Code:$colours = array('blue' => 15, 'red' => 21, 'green' => 55);
Is there a way to do this please without looping through the array()
Thanks
DD
| SitePoint Sponsor |




Hi Guys
Please help me
Suppose I have an array()
I want to find out the $colour with the highest value.Code:$colours = array('blue' => 15, 'red' => 21, 'green' => 55);
Is there a way to do this please without looping through the array()
Thanks
DD




This should do the trick:
We get the array keys of the max value (which returns an array itself), then take the first value.PHP Code:$maxs = array_keys($colours, max($colours));
$colour = $maxs[0];
or you could just asort the array.




Bookmarks