Home >>PHP Math Functions >PHP max() Function

PHP max() Function

PHP max() Function

PHP max() function is used to find the numerically maximum value in the given input array or the numerically maximum value of several specified values passed as arguments. It can accept an array or several numbers as an argument and return the numerically maximum value among all the passed parameters. Its return type is not fixed, it can be either an integer value or a float value based on the given input.

Syntax:

max(array());
 Or
max(value1,value2,...);

Parameter Values

Parameter Description
Array This is a required parameter. This parameter defines an array containing the values.
value1,value2,... This is a required parameter. This parameter defines the values to compare. It must be at least two values in this.

Here is an example of max() function in PHP:

<html>
<body>

<?php

echo max(1,2,3,4,5,6,7,8,9)."<br>";
echo max(22,44,67,12,45,63)."<br>";
echo max(63,63,834,165,15,11)."<br>";
echo max(73,1,47,82,74,19,22)."<br>";

?>

</body>
</html>
Output:
9
67
834
82

Here is another example of max() function in PHP:

<html>
<body>

<?php
$arr1 = array(73,1,47,82,74,19,22);
$arr2 = array(63,63,834,165,15,11);

echo max(1,2,3,4,5,6,7,8,9)."<br>";
echo max(array(1,2,3,4,5,6,7,8,9))."<br>";
echo max(array(22,44,67,12,45,63))."<br>";
echo max($arr1)."<br>";
echo max($arr2)."<br>";

?>

</body>
</html>
Output:
9
9
67
82
834

No Sidebar ads