3v4l.org

run code in 300+ PHP versions simultaneously
<?php $firstArr = [ ['id' => 'old_id_1', 'color' => 'red'], ['id' => 'old_id_2', 'color' => 'blue'], ['id' => 'old_id_3', 'color' => 'green'], ['id' => 'old_id_4', 'color' => 'purple'], ['id' => 'old_id_5', 'color' => 'yellow'], ]; $secondArr = [ ['id' => 'new_id_1', 'color' => 'blue'], ['id' => 'new_id_2', 'color' => 'pink'], ['id' => 'new_id_3', 'color' => 'purple'], ]; $firstArrAssoc = array_combine(array_column($firstArr, 'color'), array_column($firstArr, 'id')); $duplicatesArr = []; foreach ($secondArr as $row) { if (array_key_exists($row['color'], $firstArrAssoc)) { $duplicatesArr[] = "- $row[color] ($row[id]) in {$firstArrAssoc[$row['color']]}"; } } echo "We find " . count($duplicatesArr) . " duplicates colors :\n"; echo implode("\n", $duplicatesArr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 34
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 34
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 33
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 33
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/cAPBT
function name:  (null)
number of ops:  45
compiled vars:  !0 = $firstArr, !1 = $secondArr, !2 = $firstArrAssoc, !3 = $duplicatesArr, !4 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   17     2        INIT_FCALL                                               'array_combine'
          3        INIT_FCALL                                               'array_column'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 'color'
          6        DO_ICALL                                         $7      
          7        SEND_VAR                                                 $7
          8        INIT_FCALL                                               'array_column'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 'id'
         11        DO_ICALL                                         $8      
         12        SEND_VAR                                                 $8
         13        DO_ICALL                                         $9      
         14        ASSIGN                                                   !2, $9
   18    15        ASSIGN                                                   !3, <array>
   19    16      > FE_RESET_R                                       $12     !1, ->34
         17    > > FE_FETCH_R                                               $12, !4, ->34
   20    18    >   FETCH_DIM_R                                      ~13     !4, 'color'
         19        ARRAY_KEY_EXISTS                                         ~13, !2
         20      > JMPZ                                                     ~14, ->33
   21    21    >   ROPE_INIT                                     6  ~21     '-++'
         22        FETCH_DIM_R                                      ~16     !4, 'color'
         23        ROPE_ADD                                      1  ~21     ~21, ~16
         24        ROPE_ADD                                      2  ~21     ~21, '+%28'
         25        FETCH_DIM_R                                      ~17     !4, 'id'
         26        ROPE_ADD                                      3  ~21     ~21, ~17
         27        ROPE_ADD                                      4  ~21     ~21, '%29+in+'
         28        FETCH_DIM_R                                      ~18     !4, 'color'
         29        FETCH_DIM_R                                      ~19     !2, ~18
         30        ROPE_END                                      5  ~20     ~21, ~19
         31        ASSIGN_DIM                                               !3
         32        OP_DATA                                                  ~20
   19    33    > > JMP                                                      ->17
         34    >   FE_FREE                                                  $12
   24    35        COUNT                                            ~24     !3
         36        CONCAT                                           ~25     'We+find+', ~24
         37        CONCAT                                           ~26     ~25, '+duplicates+colors+%3A%0A'
         38        ECHO                                                     ~26
   25    39        INIT_FCALL                                               'implode'
         40        SEND_VAL                                                 '%0A'
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                         $27     
         43        ECHO                                                     $27
         44      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.35 ms | 1082 KiB | 16 Q