a1amattyj Posted February 24, 2010 Share Posted February 24, 2010 Hi, How do i select the highest key from an array, e.g: array(4) { ["Double-Glazing"]=> int(3) ["test"]=> int(1) ["test2"]=> int(1) ["test5"]=> int(7) } How do i select the "test5" only as it has the highest int? Thanks! Link to comment https://forums.phpfreaks.com/topic/193246-select-high-from-array/ Share on other sites More sharing options...
Goat Posted February 24, 2010 Share Posted February 24, 2010 $arr = array('keya' => 11 , 'keyb' => 3, 'keyc' => 15, 'keyd' => 4); foreach ($arr as $key=>$val) { if($highest < $val) { $highest = $val; $highest_key = $key; } } echo $highest_key; Goat Link to comment https://forums.phpfreaks.com/topic/193246-select-high-from-array/#findComment-1017534 Share on other sites More sharing options...
alpine Posted February 24, 2010 Share Posted February 24, 2010 Not sure i fully understand what you are doing, but look at <?php $values = array("Double-Glazing" => 3, "test" => 1, "test2" => 1, "test5" => 7); rsort($values); echo $values[0]; // 7 ?> Link to comment https://forums.phpfreaks.com/topic/193246-select-high-from-array/#findComment-1017543 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.