PHP max

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

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 :

  1. echo "max of array(4, 14, 3, 5, 14.2) is ". max(array(4,14,3,5,14.2)) . "
    " ;  

  2. echo "max of 4, -14, 2, 5, 7 is " . max(4,-14,2,5,7) . "
    " ;  

  3. echo " max of .1, .001, .2, -.5 is " . max(.1,.001,.2,-.5);  

  4. ?>   

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

 

Example - 2 :

  1. echo "max of abcd, bcde, zecd, a12gh  is : " . max('abcd', 'bcde', 'zecd', 'a12gh') . "
    " ;  

  2. echo "max of ABCD, DECD, HJKYG, PWE093 is " . max('ABCD', 'DECD', 'HJKYG', 'PWE093') . "
    " ;  

  3. ?>  

Output :

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