4.15.1 Problem
You have an array of elements, and you
want to find the largest or smallest valued element. For example, you want to
find the appropriate scale when creating a histogram.
4.15.2 Solution
$largest = max($array);
$smallest = min($array);
4.15.3 Discussion
Normally, max( ) returns the larger of two elements,
but if you pass it an array, it searches the entire array instead.
Unfortunately, there's no way to find the index of the largest element using
max( ). To do that, you
must sort the array in reverse order to put the largest element in position 0:
arsort($array);
Now the value of the largest element is $array[0].
$copy = $array; arsort($copy);