Array Maximum Minimum value

We can calculate maximum value among the elements of an array by using max function. Here is a simple example.
echo max($ar); // output is 58
Another example
echo max($ar);// output is 25

Key of the maximum value in array

To get the key of the maximum value of the array we have to use array_keys function.
echo max($ar);
$b= array_keys($ar,max($ar));
echo $b[0];
We can use this in string arrays also.
echo max($a); //optput is Welcome

Min function

We can use min function also in same way to get the minimum value from the array. Here is the example.
echo min($ar);

Example with two max value

$value= array(2,5,6,8,9,4,9,1);
echo "Maximum value = ".max($value);
Output is
Maximum value = 9
Visitors Rating
Your Rating



if there are duplicate values or if the minimum value is twice in the array?


example with two maximum value is added

Post Comment This is for short comments only. Use the forum for more discussions.

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2018 All rights reserved worldwide Privacy Policy Disclaimer