In PHP, min() returns the lowest value from a list of values or from an array.
You can call it with several separate values, like min(3, 9, 5), or pass a single array. It works with numbers and strings.
Syntax
Call min() with the values you need. Start with this line.
PHP
$lowest = min(3, 9, 5);
Call
What it does
min(3, 9, 5)
Returns 3, the smallest of the three values.
min([4, 12, 7])
Returns 4, the smallest item in the array.
min(2.5, 2)
Returns 2.
min() returns the original value, so the type stays the same. It is often combined with max() to keep a number inside a range. An empty array throws a ValueError in PHP 8.
Library declarations
PHP
min(mixed $value, mixed ...$values): mixed
Parameters
Parameter
Description
value
Required. Either an array of values to compare, or the first value to compare.
values
Optional. Any number of extra values to compare when the first argument is not an array.
Return Value
Return Value
Description
mixed
The lowest value found, returned exactly as it was passed in.
PHP Examples
Example 1 — Find the Smallest Number
Pass separate values or a single array to find the lowest one.