What is max() in PHP?

The max() function in PHP returns the maximum value in an array or from a series of values.

The illustration below shows the visual representation of the max() function.

Figure 1: Visual representation of max() function

Syntax

max(value-1, value-2, value-3...value-n)
or 
max(array)

Parameters

The max() function requires either an array or a series of values separated by commas.

Return value

This function returns the maximum value in an array or from a series of values.

Code

<?php
#series of values
echo("max(1,5,3,7,0): ");
echo (max(1,5,3,7,0));
echo("\n");
echo("max(1,-5,3,-7,0): ");
echo (max(1,-5,3,-7,0));
echo("\n");
#array
echo("max(array(-1,-5,-3,-7,0)): ");
echo (max(array(-1,-5,-3,-7,0)));
echo("\n");
echo("max(array(-1,5,-3,7,0)): ");
echo (max(array(-1,5,-3,7,0)));
echo("\n");
?>
New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources