min
Returns the smallest of the values.
Syntax
min(mixed $value, mixed ...$values): mixedParameters
| Parameter | Type | Description |
|---|---|---|
| $value | mixed | The first value, or an array of values. |
| ...$values | mixed | The other values. |
Return value
mixedThe smallest value.
Examples
Several arguments or one array:
<?php
echo min(4, 9, 2), "\n";
echo min([4, 9, 2]);Output:
2
2Capping a value from above:
<?php
$requested = 250;
echo min($requested, 100);Output:
100Notes
For an empty array the function throws a ValueError — check the array before the call.
See also
Related recipes
In the tutorial
- Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.