3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ ['foodType' => 'fruits', 'itemID' => 1, 'itemName' => 'apple'], ['foodType' => 'fruits', 'itemID' => 2, 'itemName' => 'banana'], ['foodType' => 'veggies', 'itemID' => 3, 'itemName' => 'carrot'], ['foodType' => 'veggies', 'itemID' => 4, 'itemName' => 'broccoli'] ]; function array_column_multi ($array, $column) { $types = array_unique(array_column($array, $column)); $return = []; foreach ($types as $type) { foreach ($array as $key => $value) { if ($type === $value[$column]) { unset($value[$column]); $return[$type][] = $value; unset($array[$key]); } } } return $return; } print_r(array_column_multi($data, 'foodType'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KQVeN
function name:  (null)
number of ops:  9
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   26     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'array_column_multi'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'foodType'
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function array_column_multi:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 27
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 27
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 24
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 25
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/KQVeN
function name:  array_column_multi
number of ops:  30
compiled vars:  !0 = $array, !1 = $column, !2 = $types, !3 = $return, !4 = $type, !5 = $value, !6 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        INIT_FCALL                                               'array_unique'
          3        INIT_FCALL                                               'array_column'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $7      
          7        SEND_VAR                                                 $7
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !2, $8
   12    10        ASSIGN                                                   !3, <array>
   13    11      > FE_RESET_R                                       $11     !2, ->27
         12    > > FE_FETCH_R                                               $11, !4, ->27
   14    13    > > FE_RESET_R                                       $12     !0, ->25
         14    > > FE_FETCH_R                                       ~13     $12, !5, ->25
         15    >   ASSIGN                                                   !6, ~13
   15    16        FETCH_DIM_R                                      ~15     !5, !1
         17        IS_IDENTICAL                                             !4, ~15
         18      > JMPZ                                                     ~16, ->24
   16    19    >   UNSET_DIM                                                !5, !1
   17    20        FETCH_DIM_W                                      $17     !3, !4
         21        ASSIGN_DIM                                               $17
         22        OP_DATA                                                  !5
   18    23        UNSET_DIM                                                !0, !6
   14    24    > > JMP                                                      ->14
         25    >   FE_FREE                                                  $12
   13    26      > JMP                                                      ->12
         27    >   FE_FREE                                                  $11
   22    28      > RETURN                                                   !3
   23    29*     > RETURN                                                   null

End of function array_column_multi

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.52 ms | 950 KiB | 21 Q