3v4l.org

run code in 300+ PHP versions simultaneously
<?php $foods = [ [ 'foodType' => 'fruits', 'itemID' => 1, 'itemName' => 'apple', ], [ 'foodType' => 'fruits', 'itemID' => 2, 'itemName' => 'banana', ], [ 'foodType' => 'veggies', 'itemID' => 3, 'itemName' => 'carrot', ], [ 'foodType' => 'veggies', 'itemID' => 4, 'itemName' => 'broccoli', ] ]; $grouped_foods = []; $groupByColumn = 'foodType'; array_filter($foods, function ($foodItem) use(&$grouped_foods, $groupByColumn) { $grouped_foods[$foodItem[$groupByColumn]][] = array_filter($foodItem, function ($key) use($groupByColumn) { return $key != $groupByColumn; }, ARRAY_FILTER_USE_KEY); }); echo "<pre>"; print_R($grouped_foods); echo "</pre>";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bbX5A
function name:  (null)
number of ops:  16
compiled vars:  !0 = $foods, !1 = $grouped_foods, !2 = $groupByColumn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   29     1        ASSIGN                                                   !1, <array>
   30     2        ASSIGN                                                   !2, 'foodType'
   32     3        INIT_FCALL                                               'array_filter'
          4        SEND_VAR                                                 !0
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FbbX5A%3A32%240'
          6        BIND_LEXICAL                                             ~6, !1
          7        BIND_LEXICAL                                             ~6, !2
   36     8        SEND_VAL                                                 ~6
          9        DO_ICALL                                                 
   39    10        ECHO                                                     '%3Cpre%3E'
   40    11        INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
   41    14        ECHO                                                     '%3C%2Fpre%3E'
         15      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FbbX5A%3A32%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bbX5A
function name:  {closure}
number of ops:  15
compiled vars:  !0 = $foodItem, !1 = $grouped_foods, !2 = $groupByColumn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   33     3        FETCH_DIM_R                                      ~3      !0, !2
          4        INIT_FCALL                                               'array_filter'
          5        SEND_VAR                                                 !0
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FbbX5A%3A33%241'
          7        BIND_LEXICAL                                             ~6, !2
   35     8        SEND_VAL                                                 ~6
          9        SEND_VAL                                                 2
         10        DO_ICALL                                         $7      
   33    11        FETCH_DIM_W                                      $4      !1, ~3
         12        ASSIGN_DIM                                               $4
   35    13        OP_DATA                                                  $7
   36    14      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FbbX5A%3A32%240

Function %00%7Bclosure%7D%2Fin%2FbbX5A%3A33%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bbX5A
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $key, !1 = $groupByColumn
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   34     2        IS_NOT_EQUAL                                     ~2      !0, !1
          3      > RETURN                                                   ~2
   35     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FbbX5A%3A33%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.98 ms | 1400 KiB | 17 Q