Get max/min value/key in an associative array
by Jayanthi[ Edit ] 2013-08-28 12:49:16
Get maximum or minimum value/key in an associative array
An associative array has more than values.Get minimum value or minimum value key using min() and max() functions.
$animal = array(
"cats" => 1,
"dogs" => 2,
"fish" => 3
);
echo "Array Minimum key :".min(array_keys($animal, min($animal)));
echo "
Array Maximum key :".max(array_keys($animal, max($animal)));
echo "
Array Minimum value :".min($animal);
echo "
Array Minimum value :".max($animal);
?>
Output is :
Array Minimum key :cats
Array Maximum key :fish
Array Minimum value :1
Array Minimum value :3