3v4l.org

run code in 300+ 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 = 52
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 52
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 30
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 43
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 43
Branch analysis from position: 30
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
filename:       /in/f6FQv
function name:  (null)
number of ops:  58
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, ->52
          4    > > FE_FETCH_R                                       ~9      $8, !3, ->52
          5    >   ASSIGN                                                   !4, ~9
   18     6        INIT_FCALL                                               'in_array'
          7        FETCH_DIM_R                                      ~11     !3, 'value'
          8        SEND_VAL                                                 ~11
          9        INIT_FCALL                                               'array_column'
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 'value'
         12        DO_ICALL                                         $12     
         13        SEND_VAR                                                 $12
         14        DO_ICALL                                         $13     
         15      > JMPZ                                                     $13, ->19
   19    16    >   FETCH_DIM_R                                      ~14     !3, 'key'
         17        ASSIGN                                                   !2, ~14
   18    18      > JMP                                                      ->51
   21    19    > > JMPZ_EX                                          ~16     !2, ->30
         20    >   INIT_FCALL                                               'in_array'
         21        SEND_VAR                                                 !2
         22        INIT_FCALL                                               'array_column'
         23        SEND_VAR                                                 !1
         24        SEND_VAL                                                 'key'
         25        DO_ICALL                                         $17     
         26        SEND_VAR                                                 $17
         27        DO_ICALL                                         $18     
         28        BOOL_NOT                                         ~19     $18
         29        BOOL                                             ~16     ~19
         30    > > JMPZ                                                     ~16, ->43
   22    31    >   INIT_FCALL                                               'end'
         32        SEND_REF                                                 !1
         33        DO_ICALL                                                 
   23    34        INIT_ARRAY                                       ~22     !2, 'key'
         35        INIT_FCALL                                               'key'
         36        SEND_VAR                                                 !1
         37        DO_ICALL                                         $23     
         38        FETCH_DIM_R                                      ~24     !1, $23
         39        FETCH_DIM_R                                      ~25     ~24, 'value'
         40        ADD_ARRAY_ELEMENT                                ~22     ~25, 'value'
         41        ASSIGN_DIM                                               !1
         42        OP_DATA                                                  ~22
   25    43    >   FETCH_DIM_R                                      ~27     !3, 'key'
         44        INIT_ARRAY                                       ~28     ~27, 'key'
         45        FETCH_DIM_R                                      ~29     !3, 'value'
         46        ADD_ARRAY_ELEMENT                                ~28     ~29, 'value'
         47        ASSIGN_DIM                                               !1
         48        OP_DATA                                                  ~28
   26    49        FETCH_DIM_R                                      ~30     !3, 'key'
         50        ASSIGN                                                   !2, ~30
   17    51    > > JMP                                                      ->4
         52    >   FE_FREE                                                  $8
   29    53        ECHO                                                     '%3Cpre%3E'
   30    54        INIT_FCALL                                               'print_r'
         55        SEND_VAR                                                 !1
         56        DO_ICALL                                                 
         57      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.15 ms | 1009 KiB | 18 Q