The max Function

The max function finds the largest number among the parameters passed to it or the largest number among the elements of an array.

Syntax

phpmax(first number, second number...);
phpmax(array of numbers);

Example

Let's find the largest among the given numbers:

php<?php
  echo max(1, 2, 3);
?>

The code execution result:

php3

Example

Let's find the largest value in the array:

php<?php
  echo max([1, 2, 3]);
?>

The code execution result:

php3

See Also

  • the min function,
    which finds the smallest number