w3resource

PHP: max() function

Description

The max() function is used to find the highest value from a set of expression.

Version:

(PHP 4 and above)

Syntax:

max(array1)
 max(num1, num2, num3...)
 If the first and only parameter is an array, it returns the highest value in that array.

Parameters:

Name Description Required /
Optional
Type
array1 Specified array. Required Array
num1,num2...numn Specified numbers (at least two numbers). Required Mixed*

Return value:

Returns the numerically highest value.

Value Type: Mixed*.

*Mixed: Mixed indicates that a parameter may accept multiple (but not necessarily all) types.

Pictorial Presentation

php-math-max()

Example - 1:

<?php
echo "max of array(4, 14, 3, 5, 14.2) is ". max(array(4,14,3,5,14.2)) . "<br />" ;
echo "max of 4, -14, 2, 5, 7 is " . max(4,-14,2,5,7) . "<br />" ;
echo " max of .1, .001, .2, -.5 is " . max(.1,.001,.2,-.5);
?> 

Output:

max of array(4, 14, 3, 5, 14.2) is 14.2
max of 4, -14, 2, 5, 7 is 7
max of .1, .001, .2, -.5 is 0.2

View the example in the browser

Example - 2:

<?php
echo "max of abcd, bcde, zecd, a12gh  is : " . max('abcd', 'bcde', 'zecd', 'a12gh') . "<br />" ;
echo "max of ABCD, DECD, HJKYG, PWE093 is " . max('ABCD', 'DECD', 'HJKYG', 'PWE093') . "<br />" ;
?>

Output:

max of abcd, bcde, zecd, a12gh  is : zecd
max of ABCD, DECD, HJKYG,   PWE093 is PWE093

View the example in the browser

See also

PHP Function Reference

Previous: log
Next: min



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/function-reference/max.php