Home > Article > Backend Development > How to use php min function
PHP min() function is used to return the minimum value. The syntax is: min(X,Y,Z) or min(array(X,Y,Z)). There is at least one parameter in the min function, which can be multiple parameters or an array.
#How to use the min function?
Function: Find the minimum number from all parameters
Syntax: min(X,Y,Z) or min(array(X,Y,Z))
Parameters: There is at least one parameter in the min function, it can be multiple parameters, or it can be an array.
Note: If there is only one parameter and it is an array, the minimum value in the array will be returned. If the first parameter is an integer, a string or a floating point number, at least two parameters are required, and min will return these. The smallest value. The parameter can have an infinite number of values.
php min() function usage example 1:
<?php $i = 2; $j = 9; $k = 5; $h = min($i,$j,$k); echo "最小值是".$h; ?>
Output:
最小值是2
php min() function usage example 2:
<?php //获取数组中最小值的元素 $arr = array(9,5,8,6,3,7,4,2); print_r(min($arr)); ?>
Output:
2
This article is an introduction to the PHP min function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use php min function. For more information, please follow other related articles on the PHP Chinese website!