Get min and max value in PHP Array

后端 未结 9 1856
天涯浪人
天涯浪人 2020-11-30 00:36

I have an array like this:


array (0 => 
  array (
    \'id\' => \'20110209172713\',
    \'Date\' => \'2011-02-09\',
    \'Weight\' => \'200\',
  ),
  1 =>          


        
9条回答
  •  离开以前
    2020-11-30 01:18

    For the people using PHP 5.5+ this can be done a lot easier with array_column. Not need for those ugly array_maps anymore.

    How to get a max value:

    $highest_weight = max(array_column($details, 'Weight'));
    

    How to get the min value

    $lowest_weight = min(array_column($details, 'Weight'));
    

提交回复
热议问题