3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ ["key" => 0, "value" => 25], ["key" => 1, "value" => 25], ["key" => 2, "value" => 25], ["key" => 3, "value" => 33], ["key" => 4, "value" => 45], ["key" => 5, "value" => 66], ["key" => 6, "value" => 66], ["key" => 7, "value" => 66], ["key" => 8, "value" => 66], ["key" => 9, "value" => 55], ]; $r = []; $lastKey = ''; foreach($array as $k => $v){ if(in_array($v['value'], array_column($r, 'value'))){ $lastKey = $v['key']; }else{ if($lastKey && !in_array($lastKey, array_column($r, 'key'))){ end($r); $r[] = [ 'key' => $lastKey, 'value' => $r[key($r)]['value']]; } $r[] = [ 'key' => $v['key'] , 'value' => $v['value'] ]; $lastKey = $v['key']; } } echo '<pre>'; print_r($r);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 46
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 46
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 16
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 37
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 37
Branch analysis from position: 24
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
filename:       /in/f6FQv
function name:  (null)
number of ops:  52
compiled vars:  !0 = $array, !1 = $r, !2 = $lastKey, !3 = $v, !4 = $k
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   15     1        ASSIGN                                                       !1, <array>
   16     2        ASSIGN                                                       !2, ''
   17     3      > FE_RESET_R                                           $8      !0, ->46
          4    > > FE_FETCH_R                                           ~9      $8, !3, ->46
          5    >   ASSIGN                                                       !4, ~9
   18     6        FETCH_DIM_R                                          ~11     !3, 'value'
          7        INIT_FCALL                                                   'array_column'
          8        SEND_VAR                                                     !1
          9        SEND_VAL                                                     'value'
         10        DO_ICALL                                             $12     
         11        FRAMELESS_ICALL_2                in_array            ~13     ~11, $12
         12      > JMPZ                                                         ~13, ->16
   19    13    >   FETCH_DIM_R                                          ~14     !3, 'key'
         14        ASSIGN                                                       !2, ~14
   18    15      > JMP                                                          ->45
   21    16    > > JMPZ_EX                                              ~16     !2, ->24
         17    >   INIT_FCALL                                                   'array_column'
         18        SEND_VAR                                                     !1
         19        SEND_VAL                                                     'key'
         20        DO_ICALL                                             $17     
         21        FRAMELESS_ICALL_2                in_array            ~18     !2, $17
         22        BOOL_NOT                                             ~19     ~18
         23        BOOL                                                 ~16     ~19
         24    > > JMPZ                                                         ~16, ->37
   22    25    >   INIT_FCALL                                                   'end'
         26        SEND_REF                                                     !1
         27        DO_ICALL                                                     
   23    28        INIT_ARRAY                                           ~22     !2, 'key'
         29        INIT_FCALL                                                   'key'
         30        SEND_VAR                                                     !1
         31        DO_ICALL                                             $23     
         32        FETCH_DIM_R                                          ~24     !1, $23
         33        FETCH_DIM_R                                          ~25     ~24, 'value'
         34        ADD_ARRAY_ELEMENT                                    ~22     ~25, 'value'
         35        ASSIGN_DIM                                                   !1
         36        OP_DATA                                                      ~22
   25    37    >   FETCH_DIM_R                                          ~27     !3, 'key'
         38        INIT_ARRAY                                           ~28     ~27, 'key'
         39        FETCH_DIM_R                                          ~29     !3, 'value'
         40        ADD_ARRAY_ELEMENT                                    ~28     ~29, 'value'
         41        ASSIGN_DIM                                                   !1
         42        OP_DATA                                                      ~28
   26    43        FETCH_DIM_R                                          ~30     !3, 'key'
         44        ASSIGN                                                       !2, ~30
   17    45    > > JMP                                                          ->4
         46    >   FE_FREE                                                      $8
   29    47        ECHO                                                         '%3Cpre%3E'
   30    48        INIT_FCALL                                                   'print_r'
         49        SEND_VAR                                                     !1
         50        DO_ICALL                                                     
         51      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
178.01 ms | 2282 KiB | 17 Q