4.15. Finding the Largest or Smallest Valued Element in an Array
$largest = max($array);
$smallest = min($array);
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:
Now the value of the largest element is $array.
$copy = $array; arsort($copy);
4.15.4. See Also
Copyright © 2003 O'Reilly & Associates. All rights reserved.