3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr= [ ['attr_id' => 1,'name' => 'qty','value' =>'100'], ['attr_id' => 1,'name'=>'qty','value'=>'200'], ['attr_id'=>1,'name'=>'qty','value'=>'500'], ['attr_id'=>2,'name'=>'price','value'=>'10$']]; $value = array_column($arr, 'value'); $id = array_column($arr, 'attr_id'); $res =[]; Foreach($id as $key => $i){ If(!isset($res[$i])) $res[$i] = ['attr_id' => $i, 'name'=>'qty', 'value' => []]; $res[$i]['value'][] = $value[$key]; } Var_dump($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 29
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 29
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 23
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/VXI5E
function name:  (null)
number of ops:  34
compiled vars:  !0 = $arr, !1 = $value, !2 = $id, !3 = $res, !4 = $i, !5 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    8     1        INIT_FCALL                                                   'array_column'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     'value'
          4        DO_ICALL                                             $7      
          5        ASSIGN                                                       !1, $7
    9     6        INIT_FCALL                                                   'array_column'
          7        SEND_VAR                                                     !0
          8        SEND_VAL                                                     'attr_id'
          9        DO_ICALL                                             $9      
         10        ASSIGN                                                       !2, $9
   10    11        ASSIGN                                                       !3, <array>
   11    12      > FE_RESET_R                                           $12     !2, ->29
         13    > > FE_FETCH_R                                           ~13     $12, !4, ->29
         14    >   ASSIGN                                                       !5, ~13
   12    15        ISSET_ISEMPTY_DIM_OBJ                             0  ~15     !3, !4
         16        BOOL_NOT                                             ~16     ~15
         17      > JMPZ                                                         ~16, ->23
         18    >   INIT_ARRAY                                           ~18     !4, 'attr_id'
         19        ADD_ARRAY_ELEMENT                                    ~18     'qty', 'name'
         20        ADD_ARRAY_ELEMENT                                    ~18     <array>, 'value'
         21        ASSIGN_DIM                                                   !3, !4
         22        OP_DATA                                                      ~18
   13    23    >   FETCH_DIM_R                                          ~22     !1, !5
         24        FETCH_DIM_W                                          $19     !3, !4
         25        FETCH_DIM_W                                          $20     $19, 'value'
         26        ASSIGN_DIM                                                   $20
         27        OP_DATA                                                      ~22
   11    28      > JMP                                                          ->13
         29    >   FE_FREE                                                      $12
   15    30        INIT_FCALL                                                   'var_dump'
         31        SEND_VAR                                                     !3
         32        DO_ICALL                                                     
         33      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.59 ms | 2107 KiB | 15 Q