abdfahim Posted August 13, 2012 Share Posted August 13, 2012 I want to get the maximum values of the second key of a multidimensional array. Write now I am using the code below, which works. But interested to know whether anybody has any better idea? $arr['a']['2012-08-04']=100; $arr['a']['2012-08-01']=4545; $arr['a']['2012-08-07']=2434; $arr['b']['2012-08-02']=2334; $arr['b']['2012-08-03']=2324; $dt=array(); foreach($arr as $val){ $dt=array_merge($dt,$val); } echo max(array_keys($dt)); Quote Link to comment https://forums.phpfreaks.com/topic/267003-maximum-secondary-key-in-a-multidimensional-array/ Share on other sites More sharing options...
Barand Posted August 13, 2012 Share Posted August 13, 2012 $max = ''; foreach ($arr as $k1=>$v1) { foreach ($v1 as $k=>$v) $max=max($max, $k); } echo $max.'<br />'; Quote Link to comment https://forums.phpfreaks.com/topic/267003-maximum-secondary-key-in-a-multidimensional-array/#findComment-1368918 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.