echo max(4,8,2); // 8
echo "<br>";
echo max(5,-1,0); // 5
echo "<br>";
echo max(2,0,-3); // 2
echo "<br>";
echo max(array(4,6,1)); // 6
echo "<br>";
echo max('plus2net',5,-2);// plus2net
echo "<br>";
echo max('abcd',5,0);// abcd
echo "<br>";
echo max('hello', 1); // hello
echo "<br><BR>";
echo max(0, 'hello'); // hello
echo "<br>";
echo max('hello', 0); // hello
Syntax
MAX(value1,value2,value3....);
We can get maximum value or highest number between two variables or two numbers by using max function. We can use more than two numbers also. Here is the code.
<?Php
echo max(5,25,6,-22,-66); // Output is 25
?>
<?Php
echo max(-2.5,'plus2net'); // Output plus2net
echo max(0,'plus2net'); // Output is 0, when values are equal the order decides the output
echo max(3,'plus2net'); //Output is 3
?>
<?Php
echo max(array(3,15,-5)); //Output is 15
?>
$result = max(strlen('apple'), strlen('banana'), strlen('cherry'));
echo $result; // Output: 6
$array = [10, 50, 30, 90, 40];
echo max($array); // Output: 90
$result = max(10, 'apple');
echo ($result); // Output: apple (as it compares lexicographically)
Read More on max value of Array
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.