max(): Maximum number

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 
?>

Max with String

We can find out maximum by comparing one string wth a number. Here string will be treated as 0 and then compared.
<?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
?>

Max with array

<?Php
echo max(array(3,15,-5)); //Output is 15
?>

Example: Finding Maximum String Length

$result = max(strlen('apple'), strlen('banana'), strlen('cherry'));
echo $result;  // Output: 6

Example: Maximum Value in an Array

$array = [10, 50, 30, 90, 40];
echo max($array);  // Output: 90

Example: Mixed Data Types

$result = max(10, 'apple');
echo ($result);  // Output: apple (as it compares lexicographically)

Read More on max value of Array


Math Functions min()
decbin() Binary equivalent of decimal number
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com











    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer