Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

min

Returns the smallest of the values.

Syntax

min(mixed $value, mixed ...$values): mixed

Parameters

ParameterTypeDescription
$valuemixedThe first value, or an array of values.
...$valuesmixedThe 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
2

Capping a value from above:

<?php
 
$requested = 250;
 
echo min($requested, 100);

Output:

100

Notes

For an empty array the function throws a ValueError — check the array before the call.

See also

  • max — Returns the largest of the given values.
  • sort — Sorts an array in ascending order.

Related recipes

In the tutorial

  • Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.

Thanks for reading!

Donate to the site — we work hard for you.