# Array Maximum Minimum value

We can calculate maximum value among the elements of an array by using max function. Here is a simple example.
``````\$ar=array(25,26,47,14,29,58,15);
echo max(\$ar); // output is 58
``````
Another example
``````\$ar=array(1=>15,3=>25,4=>13,5=>10);
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.
``````\$ar=array(1=>15,3=>25,4=>13,5=>10);
echo max(\$ar);
\$b= array_keys(\$ar,max(\$ar));
echo \$b[0];
``````
We can use this in string arrays also.
``````\$a=array('Welcome',0);
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.
``````\$ar=array(25,26,47,14,29,58,15);
echo min(\$ar);
``````

## Example with two max value

``````<?Php
\$value= array(2,5,6,8,9,4,9,1);
echo "Maximum  value = ".max(\$value);
?>``````
Output is
``Maximum value = 9``
Visitors Rating

 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

Post your comments , suggestion , error , requirements etc here .