The function to find the maximum value of an array in php is "max()". The max() function can receive an array parameter containing multiple values, the syntax "max(array_values)", it will calculate and return the maximum value in the "array_values" array; it can also receive multiple comparison value parameters, the syntax "max(value1 ,value2,...)", will calculate and return the largest one among multiple specified values.
The operating environment of this tutorial: windows7 system, PHP version 8.1, DELL G3 computer
Find the maximum value of an array in php The function is "max()".
PHP max() function
max() function can return the maximum value in an array, or several specified values the maximum value in .
There are two syntaxes for the max() function:
1. Receive an array parameter containing multiple values
max(array_values);
array_values
: Required. Specifies an array containing values.
Return value: the maximum value in the array
2. Receive multiple comparison value parameters
max(value1,value2,...);
## value1,value2,... : required. Specifies the values to be compared (at least two values).
max() function usage example:
Example 1: Find the maximum value in the array<?php header("Content-type:text/html;charset=utf-8"); $arr=array(3,5,23,6,28,6,7,1); var_dump($arr); echo "最大值为:".max($arr); ?>
<?php echo(max(2,4,6,8,10) . "<br>"); echo(max(22,14,68,18,15) . "<br>"); echo(max(array(4,6,8,10)) . "<br>"); echo(max(array(44,16,81,12))); ?>
PHP Video Tutorial"
The above is the detailed content of What is the function to find the maximum value of an array in php?. For more information, please follow other related articles on the PHP Chinese website!