3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = [ [ 'id' => 1, 'user_id' => 9788, 'contact_id' => 10083, 'product_id' => 1, 'category_id' => 23, 'grade' => 'A', 'point' => 89, ], [ 'id' => 1, 'user_id' => 9788, 'contact_id' => 10083, 'product_id' => 2, 'category_id' => 27, 'grade' => 'A', 'point' => 89, ] ]; $groupedArr = array_reduce($arr, function ($a, $c) { $a[$c['user_id']] = [ 'user_id' => $c['user_id'], 'contact_id' => $c['contact_id'], 'attributes' => array_merge([[ 'product_id' => $c['product_id'], 'category_id' => $c['category_id'] ]], $a[$c['user_id']]['attributes'] ?? []), 'grade' => $c['grade'], 'point' => $c['point'] ]; return $a; }, []); echo json_encode(array_values($groupedArr), JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WMvXt
function name:  (null)
number of ops:  17
compiled vars:  !0 = $arr, !1 = $groupedArr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   22     1        INIT_FCALL                                                   'array_reduce'
          2        SEND_VAR                                                     !0
          3        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
   34     4        SEND_VAL                                                     ~3
          5        SEND_VAL                                                     <array>
   22     6        DO_ICALL                                             $4      
          7        ASSIGN                                                       !1, $4
   35     8        INIT_FCALL                                                   'json_encode'
          9        INIT_FCALL                                                   'array_values'
         10        SEND_VAR                                                     !1
         11        DO_ICALL                                             $6      
         12        SEND_VAR                                                     $6
         13        SEND_VAL                                                     128
         14        DO_ICALL                                             $7      
         15        ECHO                                                         $7
         16      > 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/WMvXt
function name:  {closure:/in/WMvXt:22}
number of ops:  30
compiled vars:  !0 = $a, !1 = $c
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   23     2        FETCH_DIM_R                                          ~2      !1, 'user_id'
   24     3        FETCH_DIM_R                                          ~4      !1, 'user_id'
          4        INIT_ARRAY                                           ~5      ~4, 'user_id'
   25     5        FETCH_DIM_R                                          ~6      !1, 'contact_id'
          6        ADD_ARRAY_ELEMENT                                    ~5      ~6, 'contact_id'
   26     7        INIT_FCALL                                                   'array_merge'
   27     8        FETCH_DIM_R                                          ~7      !1, 'product_id'
          9        INIT_ARRAY                                           ~8      ~7, 'product_id'
   28    10        FETCH_DIM_R                                          ~9      !1, 'category_id'
         11        ADD_ARRAY_ELEMENT                                    ~8      ~9, 'category_id'
         12        INIT_ARRAY                                           ~10     ~8
         13        SEND_VAL                                                     ~10
   29    14        FETCH_DIM_R                                          ~11     !1, 'user_id'
         15        FETCH_DIM_IS                                         ~12     !0, ~11
         16        FETCH_DIM_IS                                         ~13     ~12, 'attributes'
         17        COALESCE                                             ~14     ~13
         18        QM_ASSIGN                                            ~14     <array>
         19        SEND_VAL                                                     ~14
   26    20        DO_ICALL                                             $15     
   29    21        ADD_ARRAY_ELEMENT                                    ~5      $15, 'attributes'
   30    22        FETCH_DIM_R                                          ~16     !1, 'grade'
         23        ADD_ARRAY_ELEMENT                                    ~5      ~16, 'grade'
   31    24        FETCH_DIM_R                                          ~17     !1, 'point'
         25        ADD_ARRAY_ELEMENT                                    ~5      ~17, 'point'
   23    26        ASSIGN_DIM                                                   !0, ~2
   31    27        OP_DATA                                                      ~5
   33    28      > RETURN                                                       !0
   34    29*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
136.44 ms | 1523 KiB | 17 Q