Home >Backend Development >PHP Problem >What is the function to find the maximum value of an array in php?

What is the function to find the maximum value of an array in php?

青灯夜游
青灯夜游Original
2022-06-29 19:12:562897browse

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.

What is the function to find the maximum value of an array in php?

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).

Return value: the maximum value among multiple specified 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);
?>

What is the function to find the maximum value of an array in php?

Example 2: Find the maximum value among multiple specified values

<?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)));
?>

What is the function to find the maximum value of an array in php?

Recommended learning: "

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!

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