How to group subarrays by a column value?

前端 未结 18 2076
一生所求
一生所求 2020-11-22 10:43

I have the following array

Array
(
    [0] => Array
        (
            [id] => 96
            [shipping_no] => 212755-1
            [part_no] =&         


        
18条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 11:22

    In a more functional programming style, you could use array_reduce

    $groupedById = array_reduce($data, function (array $accumulator, array $element) {
      $accumulator[$element['id']][] = $element;
    
      return $accumulator;
    }, []);
    

提交回复
热议问题