3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => [ 'id' => 20, 'name' => 'Test' ], 1 => [ 'id' => 20, 'name' => 'Test1' ], 2 => [ 'id' => 12, 'name' => 'Test2' ], 3 => [ 'id' => 24, 'name' => 'Test3' ] ]; $arr = $currentValue = $previousValue = ['id' => '']; foreach($array as $key => $value) { $currentValue = [ 'id' => $previousValue['id'] === $value['id'] ? '' : $value['id'], 'name' => $value['name'] ]; $arr[] = $previousValue = $currentValue; } var_dump($arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 23
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/PcQg1
function name:  (null)
number of ops:  28
compiled vars:  !0 = $array, !1 = $arr, !2 = $currentValue, !3 = $previousValue, !4 = $value, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   22     1        ASSIGN                                           ~7      !3, <array>
          2        ASSIGN                                           ~8      !2, ~7
          3        ASSIGN                                                   !1, ~8
   23     4      > FE_RESET_R                                       $10     !0, ->23
          5    > > FE_FETCH_R                                       ~11     $10, !4, ->23
          6    >   ASSIGN                                                   !5, ~11
   25     7        FETCH_DIM_R                                      ~13     !3, 'id'
          8        FETCH_DIM_R                                      ~14     !4, 'id'
          9        IS_IDENTICAL                                             ~13, ~14
         10      > JMPZ                                                     ~15, ->13
         11    >   QM_ASSIGN                                        ~16     ''
         12      > JMP                                                      ->15
         13    >   FETCH_DIM_R                                      ~17     !4, 'id'
         14        QM_ASSIGN                                        ~16     ~17
         15    >   INIT_ARRAY                                       ~18     ~16, 'id'
   26    16        FETCH_DIM_R                                      ~19     !4, 'name'
         17        ADD_ARRAY_ELEMENT                                ~18     ~19, 'name'
   24    18        ASSIGN                                                   !2, ~18
   29    19        ASSIGN                                           ~22     !3, !2
         20        ASSIGN_DIM                                               !1
         21        OP_DATA                                                  ~22
   23    22      > JMP                                                      ->5
         23    >   FE_FREE                                                  $10
   32    24        INIT_FCALL                                               'var_dump'
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.4 ms | 1400 KiB | 15 Q