PHP min() Function
Definition and Usage
min() returns the minimum value.
Syntax
min(x,y)
Parameter | Description |
---|---|
x | Required. A number. |
y | Required. A number. |
Description
min() returns the smallest number in the parameters.
If only one parameter is an array, min() returns the smallest value in that array. If the first parameter is an integer, string, or floating-point number, at least two parameters are required and min() will return the smallest of these values. You can compare an unlimited number of values.
Tips and Comments
Note:PHP will treat non-numeric strings as 0, but if this is the actual smallest number, it will still return a string. If multiple parameters are evaluated to 0 and are the smallest, min() will return the smallest string in alphabetical order, or 0 if there are no strings. If there are no strings, it will return the numeric 0.
Example
In this example, we will use min() to return the minimum of two specified numbers:
<?php echo(min(5,7)); echo(min(-3,5)); echo(min(-3,-5)); echo(min(7.25,7.30)); ?>
Output similar to:
5 -3 -5 7.25