3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json1 = '{ "d": [{"A": 0,"B": "foo1","C": "bar1","D": "real1","E": 0}, {"A": 1,"B": "foo2","C": "bar2","D": "real2","E": 1}, {"A": 2,"B": "foo3","C": "bar3","D": "real3","E": 2} ] }'; $json2 = '{ "A": ["this1","this2","this3"], "E": ["last1","last2","last3"] }'; $array1 = json_decode($json1, true); $array2 = json_decode($json2, true); foreach ($array1['d'] as &$arr) { foreach ($arr as $key => &$value) { if (array_key_exists($key, $array2)) { $value = $array2[$key][$value]; } } } echo json_encode($array1, JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 14, Position 2 = 26
Branch analysis from position: 14
2 jumps found. (Code = 126) Position 1 = 15, Position 2 = 26
Branch analysis from position: 15
2 jumps found. (Code = 125) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
2 jumps found. (Code = 126) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 23
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 24
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/KKk8b
function name:  (null)
number of ops:  33
compiled vars:  !0 = $json1, !1 = $json2, !2 = $array1, !3 = $array2, !4 = $arr, !5 = $value, !6 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7B+%22d%22%3A+%5B%7B%22A%22%3A+0%2C%22B%22%3A+%22foo1%22%2C%22C%22%3A+%22bar1%22%2C%22D%22%3A+%22real1%22%2C%22E%22%3A+0%7D%2C%0A++++++%7B%22A%22%3A+1%2C%22B%22%3A+%22foo2%22%2C%22C%22%3A+%22bar2%22%2C%22D%22%3A+%22real2%22%2C%22E%22%3A+1%7D%2C%0A++++++%7B%22A%22%3A+2%2C%22B%22%3A+%22foo3%22%2C%22C%22%3A+%22bar3%22%2C%22D%22%3A+%22real3%22%2C%22E%22%3A+2%7D+%5D+%7D'
    6     1        ASSIGN                                                   !1, '%7B+%22A%22%3A+%5B%22this1%22%2C%22this2%22%2C%22this3%22%5D%2C%0A++++%22E%22%3A+%5B%22last1%22%2C%22last2%22%2C%22last3%22%5D+%7D'
    9     2        INIT_FCALL                                               'json_decode'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $9      
          6        ASSIGN                                                   !2, $9
   10     7        INIT_FCALL                                               'json_decode'
          8        SEND_VAR                                                 !1
          9        SEND_VAL                                                 <true>
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !3, $11
   12    12        FETCH_DIM_W                                      $13     !2, 'd'
         13      > FE_RESET_RW                                      $14     $13, ->26
         14    > > FE_FETCH_RW                                              $14, !4, ->26
   13    15    > > FE_RESET_RW                                      $15     !4, ->24
         16    > > FE_FETCH_RW                                      ~16     $15, !5, ->24
         17    >   ASSIGN                                                   !6, ~16
   14    18        ARRAY_KEY_EXISTS                                         !6, !3
         19      > JMPZ                                                     ~18, ->23
   15    20    >   FETCH_DIM_R                                      ~19     !3, !6
         21        FETCH_DIM_R                                      ~20     ~19, !5
         22        ASSIGN                                                   !5, ~20
   13    23    > > JMP                                                      ->16
         24    >   FE_FREE                                                  $15
   12    25      > JMP                                                      ->14
         26    >   FE_FREE                                                  $14
   19    27        INIT_FCALL                                               'json_encode'
         28        SEND_VAR                                                 !2
         29        SEND_VAL                                                 128
         30        DO_ICALL                                         $22     
         31        ECHO                                                     $22
         32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.68 ms | 1016 KiB | 15 Q