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

How to use php max function

藏色散人
藏色散人Original
2019-01-30 10:15:276804browse

php max() function is used to find the maximum value. The syntax is max(X,Y,Z) or max(array(X,Y,Z)). There is at least one parameter in the max function, it can be multiple parameters, or it can be an array.

How to use php max function

#How to use max function?

Function: Find the maximum number from all parameters

Syntax: max(X,Y,Z) or max(array(X,Y,Z))

Parameters: There is at least one parameter in the max 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 maximum 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 max will return these. The largest of the values. The parameter can have unlimited values.

php max() function usage example 1:

<?php
$i = 2;
$j = 9;
$k = 5;
$h = max($i,$j,$k);
echo "最大值是".$h;
?>

Output:

最大值是9

php max() function usage example 2:

<?php
//获取数组中最大值的元素
$arr = array(15,16,88,54,79,33,159);
print_r(max($arr));
?>

Output:

159

This article is an introduction to the PHP max function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use php max 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