Finding the lowest value of an array is a pretty common task in PHP, especially when you are dealing with things like scores or money. In the old days before PHP 4, finding the lowest value of an array meant looping through the array and comparing values until you had the lowest one, something like this:
$array = array(6, 2, 10, 4, 15);
$lowest = false;
foreach ($array as $value) {
if ($lowest === false || $value < $lowest) {
$lowest = $value;
}
}
Not too terrible, but definitely not very elegant. Fortunately in PHP 4+ we
have the min()
function available:
$array = array(6, 2, 10, 4, 15);
$lowest = min($array);
Not much to it!