3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input_array = [ ['id' => 2, 'name' => 'ProductName', 'comment' => 'best product comment 1'], ['id' => 2, 'name' => 'ProductName', 'comment' => 'best product comment 2'], ['id' => 2, 'name' => 'ProductName', 'comment' => 'best product comment 3'], ['id' => 3, 'name' => 'ProductName2', 'comment' => 'best product comment 4'], ['id' => 3, 'name' => 'ProductName2', 'comment' => 'best product comment 5'] ]; $output_array = array_values(array_reduce($input_array, function($output_array, $item) { if (array_key_exists($item['id'], $output_array)) $output_array[$item['id']]['comment'][] = $item['comment']; else { $item['comment'] = (array)$item['comment']; $output_array[$item['id']] = $item; } return $output_array; }, [])); var_dump($output_array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QfGYF
function name:  (null)
number of ops:  15
compiled vars:  !0 = $input_array, !1 = $output_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   10     1        INIT_FCALL                                               'array_values'
          2        INIT_FCALL                                               'array_reduce'
          3        SEND_VAR                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
   19     5        SEND_VAL                                                 ~3
          6        SEND_VAL                                                 <array>
   10     7        DO_ICALL                                         $4      
   19     8        SEND_VAR                                                 $4
   10     9        DO_ICALL                                         $5      
         10        ASSIGN                                                   !1, $5
   21    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
         14      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QfGYF
function name:  {closure}
number of ops:  21
compiled vars:  !0 = $output_array, !1 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        FETCH_DIM_R                                      ~2      !1, 'id'
          3        ARRAY_KEY_EXISTS                                         ~2, !0
          4      > JMPZ                                                     ~3, ->12
   12     5    >   FETCH_DIM_R                                      ~4      !1, 'id'
          6        FETCH_DIM_R                                      ~8      !1, 'comment'
          7        FETCH_DIM_W                                      $5      !0, ~4
          8        FETCH_DIM_W                                      $6      $5, 'comment'
          9        ASSIGN_DIM                                               $6
         10        OP_DATA                                                  ~8
   11    11      > JMP                                                      ->19
   15    12    >   FETCH_DIM_R                                      ~10     !1, 'comment'
         13        CAST                                          7  ~11     ~10
         14        ASSIGN_DIM                                               !1, 'comment'
         15        OP_DATA                                                  ~11
   16    16        FETCH_DIM_R                                      ~12     !1, 'id'
         17        ASSIGN_DIM                                               !0, ~12
         18        OP_DATA                                                  !1
   18    19    > > RETURN                                                   !0
   19    20*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.43 ms | 1070 KiB | 16 Q