3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = array( 0 => array ( 'item_id' => '1', 'store_id' => '1', 'price' => '74.99' ), 1 => array( 'item_id' => '2' , 'store_id' => '1' , 'price' => '35.99' ), 2 => array( 'item_id' => '3' , 'store_id' => '1' , 'price' => '89.99' ), 3 => array( 'item_id' => '1' , 'store_id' => '2' , 'price' => '69.99' ), 4 => array( 'item_id' => '2', 'store_id' => '2', 'price' => '39.99' ), 5 => array( 'item_id' => '3', 'store_id' => '2', 'price' => '95.99' ) ); $output = array(); foreach($arr as $item){ if(in_array($item['item_id'], array_column($output, 'item_id'))){ // add store to already existing item $key = array_search($item['item_id'], array_column($arr, 'item_id')); $output[$key]['store_id_' . $item['store_id']] = $item['price']; }else{ // add new item with store $tmp = array( 'item_id' => $item['item_id'], 'store_id_' . $item['store_id'] => $item['price'], ); $output[] = $tmp; } } echo '<pre>'; print_r($output); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 38
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 38
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 28
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/kmY30
function name:  (null)
number of ops:  44
compiled vars:  !0 = $arr, !1 = $output, !2 = $item, !3 = $key, !4 = $tmp
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   40     1        ASSIGN                                                       !1, <array>
   41     2      > FE_RESET_R                                           $7      !0, ->38
          3    > > FE_FETCH_R                                                   $7, !2, ->38
   42     4    >   FETCH_DIM_R                                          ~8      !2, 'item_id'
          5        INIT_FCALL                                                   'array_column'
          6        SEND_VAR                                                     !1
          7        SEND_VAL                                                     'item_id'
          8        DO_ICALL                                             $9      
          9        FRAMELESS_ICALL_2                in_array            ~10     ~8, $9
         10      > JMPZ                                                         ~10, ->28
   44    11    >   INIT_FCALL                                                   'array_search'
         12        FETCH_DIM_R                                          ~11     !2, 'item_id'
         13        SEND_VAL                                                     ~11
         14        INIT_FCALL                                                   'array_column'
         15        SEND_VAR                                                     !0
         16        SEND_VAL                                                     'item_id'
         17        DO_ICALL                                             $12     
         18        SEND_VAR                                                     $12
         19        DO_ICALL                                             $13     
         20        ASSIGN                                                       !3, $13
   45    21        FETCH_DIM_R                                          ~16     !2, 'store_id'
         22        CONCAT                                               ~17     'store_id_', ~16
         23        FETCH_DIM_R                                          ~19     !2, 'price'
         24        FETCH_DIM_W                                          $15     !1, !3
         25        ASSIGN_DIM                                                   $15, ~17
         26        OP_DATA                                                      ~19
   42    27      > JMP                                                          ->37
   49    28    >   FETCH_DIM_R                                          ~20     !2, 'item_id'
         29        INIT_ARRAY                                           ~21     ~20, 'item_id'
   50    30        FETCH_DIM_R                                          ~22     !2, 'store_id'
         31        CONCAT                                               ~23     'store_id_', ~22
         32        FETCH_DIM_R                                          ~24     !2, 'price'
         33        ADD_ARRAY_ELEMENT                                    ~21     ~24, ~23
   48    34        ASSIGN                                                       !4, ~21
   52    35        ASSIGN_DIM                                                   !1
         36        OP_DATA                                                      !4
   41    37    > > JMP                                                          ->3
         38    >   FE_FREE                                                      $7
   55    39        ECHO                                                         '%3Cpre%3E'
   56    40        INIT_FCALL                                                   'print_r'
         41        SEND_VAR                                                     !1
         42        DO_ICALL                                                     
   57    43      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
172.45 ms | 2764 KiB | 16 Q