3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ "id" => 96, "shipping_no" => "212755-1", "part_no" => "reterty", "description" => "tyrfyt", "packaging_type" => "PC" ], [ "id" => 96, "shipping_no" => "212755-1", "part_no" => "dftgtryh", "description" => "dfhgfyh", "packaging_type" => "PC" ], [ "id" => 97, "shipping_no" => "212755-2", "part_no" => "ZeoDark", "description" => "s%c%s%c%s", "packaging_type" => "PC" ] ]; function array_group_by($arr, array $keys) { if (!is_array($arr)) { trigger_error('array_group_by(): The first argument should be an array', E_USER_ERROR); } if (count($keys) == 0) { trigger_error('array_group_by(): The Second argument Array can not be empty', E_USER_ERROR); } // Load the new array, splitting by the target key $grouped = []; foreach ($arr as $value) { $grouped[$value[$keys[0]]][] = $value; } // Recursively build a nested grouping if more parameters are supplied // Each grouped array value is grouped according to the next sequential key if (count($keys) > 1) { foreach ($grouped as $key => $value) { $parms = array_merge([$value], [array_slice($keys, 1, count($keys))]); $grouped[$key] = call_user_func_array('array_group_by', $parms); } } return $grouped; } var_export( array_group_by($array, ['id', 'shipping_no']) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FOt6M
function name:  (null)
number of ops:  9
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   52     1        INIT_FCALL                                               'var_export'
   53     2        INIT_FCALL                                               'array_group_by'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 <array>
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
   52     7        DO_ICALL                                                 
   54     8      > RETURN                                                   1

Function array_group_by:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 25
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 53
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 52
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 52
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
Branch analysis from position: 53
Branch analysis from position: 25
Branch analysis from position: 16
Branch analysis from position: 9
filename:       /in/FOt6M
function name:  array_group_by
number of ops:  55
compiled vars:  !0 = $arr, !1 = $keys, !2 = $grouped, !3 = $value, !4 = $key, !5 = $parms
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   28     2        TYPE_CHECK                                  128  ~6      !0
          3        BOOL_NOT                                         ~7      ~6
          4      > JMPZ                                                     ~7, ->9
   29     5    >   INIT_FCALL                                               'trigger_error'
          6        SEND_VAL                                                 'array_group_by%28%29%3A+The+first+argument+should+be+an+array'
          7        SEND_VAL                                                 256
          8        DO_ICALL                                                 
   31     9    >   COUNT                                            ~9      !1
         10        IS_EQUAL                                                 ~9, 0
         11      > JMPZ                                                     ~10, ->16
   32    12    >   INIT_FCALL                                               'trigger_error'
         13        SEND_VAL                                                 'array_group_by%28%29%3A+The+Second+argument+Array+can+not+be+empty'
         14        SEND_VAL                                                 256
         15        DO_ICALL                                                 
   36    16    >   ASSIGN                                                   !2, <array>
   37    17      > FE_RESET_R                                       $13     !0, ->25
         18    > > FE_FETCH_R                                               $13, !3, ->25
   38    19    >   FETCH_DIM_R                                      ~14     !1, 0
         20        FETCH_DIM_R                                      ~15     !3, ~14
         21        FETCH_DIM_W                                      $16     !2, ~15
         22        ASSIGN_DIM                                               $16
         23        OP_DATA                                                  !3
   37    24      > JMP                                                      ->18
         25    >   FE_FREE                                                  $13
   43    26        COUNT                                            ~18     !1
         27        IS_SMALLER                                               1, ~18
         28      > JMPZ                                                     ~19, ->53
   44    29    > > FE_RESET_R                                       $20     !2, ->52
         30    > > FE_FETCH_R                                       ~21     $20, !3, ->52
         31    >   ASSIGN                                                   !4, ~21
   45    32        INIT_FCALL                                               'array_merge'
         33        INIT_ARRAY                                       ~23     !3
         34        SEND_VAL                                                 ~23
         35        INIT_FCALL                                               'array_slice'
         36        SEND_VAR                                                 !1
         37        SEND_VAL                                                 1
         38        COUNT                                            ~24     !1
         39        SEND_VAL                                                 ~24
         40        DO_ICALL                                         $25     
         41        INIT_ARRAY                                       ~26     $25
         42        SEND_VAL                                                 ~26
         43        DO_ICALL                                         $27     
         44        ASSIGN                                                   !5, $27
   46    45        INIT_USER_CALL                                0          'call_user_func_array', 'array_group_by'
         46        SEND_ARRAY                                               !5
         47        CHECK_UNDEF_ARGS                                         
         48        DO_FCALL                                      1  $30     
         49        ASSIGN_DIM                                               !2, !4
         50        OP_DATA                                                  $30
   44    51      > JMP                                                      ->30
         52    >   FE_FREE                                                  $20
   50    53    > > RETURN                                                   !2
   51    54*     > RETURN                                                   null

End of function array_group_by

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.97 ms | 1024 KiB | 19 Q