PHP Function Reference

PHP max() Function



The PHP max() function returns the maximum value in an array, or the maximum value among specified values.

Syntax

//version 1
max(array)

//version 2
max(value1, value2,...)

Parameters

array Required. Specify an array containing values to compare.
value1, value2,... Required. Specify values to compare.

Return Value

Returns the numerically maximum value.

Example:

In the example below, max() function is used to find out the maximum value among specified values.

<?php
$i = max(10, 20, 5, 100, 40, 50);
echo "The maximum value is: ".$i;
?>

The output of the above code will be:

The maximum value is: 100

Example:

In the example below, max() function to find out the maximum value in the array called MyArray.

<?php
$MyArray = array(101, 202, 15, 700, 430, 510);
$i = max($MyArray);
echo "The maximum value is: ".$i;
?>

The output of the above code will be:

The maximum value is: 700

❮ PHP Math Reference