3v4l.org

run code in 300+ PHP versions simultaneously
<?php $products = [ [ 'title' => 'Product #1', 'sku' => 53159, 'price' => 12, 'image' => 'product_01.jpg', ], [ 'title' => 'Product #2', 'sku' => 60290, 'price' => 12, 'image' => 'product_01.jpg', ], [ 'title' => 'Product #3', 'sku' => 24195, 'price' => 12, 'image' => 'product_01.jpg', ], ]; $similar_products = [ [25195, 53159], [60290, 33619], [80001, 24195], ]; $final = $products; foreach ($similar_products as [$similar, $sku]) { $index = array_search($sku, array_column($final, 'sku')); if (false === $index) { $index = array_search($similar, array_column($final, 'sku')); $final[$index]['similar'] = $sku; continue; } $final[$index]['similar'] = $similar; } print_r($final);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 38
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 38
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 34
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/1Dl62
function name:  (null)
number of ops:  43
compiled vars:  !0 = $products, !1 = $similar_products, !2 = $final, !3 = $similar, !4 = $sku, !5 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   24     1        ASSIGN                                                   !1, <array>
   30     2        ASSIGN                                                   !2, !0
   31     3      > FE_RESET_R                                       $9      !1, ->38
          4    > > FE_FETCH_R                                               $9, $10, ->38
          5    >   FETCH_LIST_R                                     $11     $10, 0
          6        ASSIGN                                                   !3, $11
          7        FETCH_LIST_R                                     $13     $10, 1
          8        ASSIGN                                                   !4, $13
          9        FREE                                                     $10
   32    10        INIT_FCALL                                               'array_search'
         11        SEND_VAR                                                 !4
         12        INIT_FCALL                                               'array_column'
         13        SEND_VAR                                                 !2
         14        SEND_VAL                                                 'sku'
         15        DO_ICALL                                         $15     
         16        SEND_VAR                                                 $15
         17        DO_ICALL                                         $16     
         18        ASSIGN                                                   !5, $16
   33    19        TYPE_CHECK                                    4          !5
         20      > JMPZ                                                     ~18, ->34
   34    21    >   INIT_FCALL                                               'array_search'
         22        SEND_VAR                                                 !3
         23        INIT_FCALL                                               'array_column'
         24        SEND_VAR                                                 !2
         25        SEND_VAL                                                 'sku'
         26        DO_ICALL                                         $19     
         27        SEND_VAR                                                 $19
         28        DO_ICALL                                         $20     
         29        ASSIGN                                                   !5, $20
   35    30        FETCH_DIM_W                                      $22     !2, !5
         31        ASSIGN_DIM                                               $22, 'similar'
         32        OP_DATA                                                  !4
   36    33      > JMP                                                      ->4
   38    34    >   FETCH_DIM_W                                      $24     !2, !5
         35        ASSIGN_DIM                                               $24, 'similar'
         36        OP_DATA                                                  !3
   31    37      > JMP                                                      ->4
         38    >   FE_FREE                                                  $9
   41    39        INIT_FCALL                                               'print_r'
         40        SEND_VAR                                                 !2
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.51 ms | 1005 KiB | 16 Q