How to use php max function

藏色散人
Release: 2023-04-04 22:08:01
Original
6749 people have browsed it

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;
?>
Copy after login

Output:

最大值是9
Copy after login

php max() function usage example 2:

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

Output:

159
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!