max
Returns the largest of the given values.
Available since: PHP 4
Syntax
max(mixed $value, mixed ...$values): mixedParameters
| Parameter | Type | Description |
|---|---|---|
| $value | mixed | The first value, or an array of values. |
| ...$values | mixed | The other values to compare. |
Return value
mixedThe largest value.
Examples
Several arguments, or a single array:
<?php
echo max(1, 5, 3), "\n";
echo max([2, 8, 4]);Output:
5
8The companion min() returns the smallest:
<?php
echo min(1, 5, 3);Output:
1Notes
Passing an empty array throws an error — check the array before the call.
See also
Related recipes
In the tutorial
- Operators — Arithmetic, comparison and logical operators in PHP, and operator precedence.