30 seconds of PHP

  Back to Home

maxN

matharrayintermediate

Returns the maximum value from the provided array.

Use array_filter() and max() to find the maximum value in an array.

function maxN($numbers)
{
  $maxValue = max($numbers);
  $maxValueArray = array_filter($numbers, function ($value) use ($maxValue) {
    return $maxValue === $value;
  });

  return count($maxValueArray);
}