Home >Backend Development >PHP Tutorial >How to use php min function

How to use php min function

藏色散人
藏色散人Original
2019-01-30 10:08:034340browse

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 php min function

#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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn