3v4l.org

run code in 500+ PHP versions simultaneously
<?php $products = array( [ 'id' => 12, 'group' => 'abc', 'name' => 'Lorem', ], [ 'id' => 12, 'group' => 'def', 'name' => 'Ipsum', ], [ 'id' => 34, 'group' => 'ghi', 'name' => 'Dolor', ], [ 'id' => 34, 'group' => 'jkl', 'name' => 'Sit', ], [ 'id' => 34, 'group' => 'mno', 'name' => 'Amet', ], ); $grouped = array_reduce($products, function ($c, $v) { $c[$v['id']][$v['group']] = $v; return $c; }, []); print_r($grouped); $products[] = [ 'id' => 34, 'group' => 'jkl', 'name' => 'Consectetur', ]; $grouped = array_reduce($products, function ($c, $v) { $c[$v['id']][$v['group']] = $v; return $c; }, []); print_r($grouped); $grouped = array_reduce($products, function ($c, $v) { $c[$v['id']][$v['group']][] = $v; return $c; }, []); print_r($grouped);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qvf6J
function name:  (null)
number of ops:  34
compiled vars:  !0 = $products, !1 = $grouped
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   21     1        INIT_FCALL                                                   'array_reduce'
          2        SEND_VAR                                                     !0
          3        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
   24     4        SEND_VAL                                                     ~3
          5        SEND_VAL                                                     <array>
   21     6        DO_ICALL                                             $4      
          7        ASSIGN                                                       !1, $4
   26     8        INIT_FCALL                                                   'print_r'
          9        SEND_VAR                                                     !1
         10        DO_ICALL                                                     
   28    11        ASSIGN_DIM                                                   !0
   29    12        OP_DATA                                                      <array>
   32    13        INIT_FCALL                                                   'array_reduce'
         14        SEND_VAR                                                     !0
         15        DECLARE_LAMBDA_FUNCTION                              ~8      [1]
   35    16        SEND_VAL                                                     ~8
         17        SEND_VAL                                                     <array>
   32    18        DO_ICALL                                             $9      
         19        ASSIGN                                                       !1, $9
   37    20        INIT_FCALL                                                   'print_r'
         21        SEND_VAR                                                     !1
         22        DO_ICALL                                                     
   39    23        INIT_FCALL                                                   'array_reduce'
         24        SEND_VAR                                                     !0
         25        DECLARE_LAMBDA_FUNCTION                              ~12     [2]
   42    26        SEND_VAL                                                     ~12
         27        SEND_VAL                                                     <array>
   39    28        DO_ICALL                                             $13     
         29        ASSIGN                                                       !1, $13
   44    30        INIT_FCALL                                                   'print_r'
         31        SEND_VAR                                                     !1
         32        DO_ICALL                                                     
         33      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qvf6J
function name:  {closure:/in/Qvf6J:21}
number of ops:  9
compiled vars:  !0 = $c, !1 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   22     2        FETCH_DIM_R                                          ~2      !1, 'id'
          3        FETCH_DIM_R                                          ~4      !1, 'group'
          4        FETCH_DIM_W                                          $3      !0, ~2
          5        ASSIGN_DIM                                                   $3, ~4
          6        OP_DATA                                                      !1
   23     7      > RETURN                                                       !0
   24     8*     > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qvf6J
function name:  {closure:/in/Qvf6J:32}
number of ops:  9
compiled vars:  !0 = $c, !1 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   32     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   33     2        FETCH_DIM_R                                          ~2      !1, 'id'
          3        FETCH_DIM_R                                          ~4      !1, 'group'
          4        FETCH_DIM_W                                          $3      !0, ~2
          5        ASSIGN_DIM                                                   $3, ~4
          6        OP_DATA                                                      !1
   34     7      > RETURN                                                       !0
   35     8*     > RETURN                                                       null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qvf6J
function name:  {closure:/in/Qvf6J:39}
number of ops:  10
compiled vars:  !0 = $c, !1 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   39     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   40     2        FETCH_DIM_R                                          ~2      !1, 'id'
          3        FETCH_DIM_R                                          ~4      !1, 'group'
          4        FETCH_DIM_W                                          $3      !0, ~2
          5        FETCH_DIM_W                                          $5      $3, ~4
          6        ASSIGN_DIM                                                   $5
          7        OP_DATA                                                      !1
   41     8      > RETURN                                                       !0
   42     9*     > RETURN                                                       null

End of Dynamic Function 2

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
208.65 ms | 3118 KiB | 15 Q