$ar=array(25,26,47,14,29,58,15);
echo max($ar); // output is 58
$ar=array(1=>15,3=>25,4=>13,5=>10);
echo max($ar);// output is 25
$ar=array(1=>15,3=>25,4=>13,5=>10);
echo max($ar); // output 25
echo "<br>";
$b= array_keys($ar,max($ar));
echo $b[0]; // output 3
echo "<br>"; // using array_search()
$key=array_search(max($ar),$ar);
echo $key; // output 3
We can use this in string arrays also.
$a=array('Welcome',0);
echo max($a); //optput is Welcome
$ar=array('b','k','l','mz','Ma','na');
echo max($ar); // output is na
$ar=array(25,26,47,14,29,58,15);
echo min($ar);
<?Php
$value= array(2,5,6,8,9,4,9,1);
echo "Maximum value = ".max($value);
?>
Output is
Maximum value = 9
$student=array('Ron'=>15,'Geek'=>25,'Alex'=>13,'Ravi'=>14);
echo "highest mark : ". max($student); // output 25
echo "<br>";
echo "Student got highest mark:".array_search(max($student),$student);
echo "<br>";
echo "Lowest mark : ". min($student); // output 13
echo "<br>";
echo "Student got Lowest mark:".array_search(min($student),$student);
Output is here.
highest mark : 25
Student got highest mark : Geek
Lowest mark : 13
Student got Lowest mark : Alex
Joining Two Arrays by array_merge
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.
| psjlakshmi | 10-11-2014 |
| if there are duplicate values or if the minimum value is twice in the array? | |
| smo | 27-03-2015 |
| example with two maximum value is added | |
10-09-2019 | |
| excellent, thank you! | |