find max() of specific multidimensional array value in php

后端 未结 3 753
醉梦人生
醉梦人生 2020-12-10 19:48

See array for example: here

Basically, I want to find the max() for array[][\'time\'] in that array. I can figure it out if I loop through it, but I was hoping there

3条回答
  •  轮回少年
    2020-12-10 20:22

    Sort the array from highest to lowest in terms of []['time'] and get the first value:

    function sort_arr($item_1, $item_2)
    {
      return $item_2['time'] - $item_1['time'];
    }
    
    usort($arr, 'sort_arr');
    
    // $arr[0] is the item with the highest time
    

提交回复
热议问题