3v4l.org

run code in 300+ PHP versions simultaneously
<?php $jsonProducts = '[ { "name": "Fluted Guard of the Moon Rider", "icon": "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KW1Zwwo4NUX4oFJZEHLbXK9QlSPcU_oAlcQk2fVOiSxMfcRlFwIBYYpbaaOA9vxv_MdC8M7tq0xoaOzvb2Z7iJxD8GsJIi0--Up9Sh0A2yr0pvZ22iJdXGdVQ5NUaQpAZGHIGG2g" }, { "name": "Lion Quiver of the Moon Rider", "icon": "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KW1Zwwo4NUX4oFJZEHLbXK9QlSPcU_oAlcQk2fVOiSxtraRVhmahdbiauwIhFlwb2aImoS7oWwzIPYwqetYeKExm9SsMAg3b7AoNz32QDkqUNtMD2lJdPGbEZgNjYx8IO6" }, { "name": "Lion Quiver of the Moon Rider", "icon": "-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KW1Zwwo4NUX4oFJZEHLbXK9QlSPcU_oAlcQk2fVOiSxtraRVhmahdbiauwIhFlwb2aImoS7oWwzIPYwqetYeKExm9SsMAg3b7AoNz32QDkqUNtMD2lJdPGbEZgNjYx8IO6" } ]'; $jsonData = '{ "data": [ { "updated_at": 1576048969000, "prices": { "last": 5300 }, "name": "Lion Quiver of the Moon Rider" }, { "updated_at": 1576048969000, "prices": { "last": 2000.12 }, "name": "T-shirts" } ] }'; echo "<pre>"; $price = json_decode($jsonData, 1)['data']; $json = json_decode($jsonProducts, 1); $bool = false; foreach($price as $key => $value) { foreach($json as $k => $value2) { if ($value['name'] === $value2['name']) { if ($bool !== true) { $json[$k]['price'] = $value['prices']['last']; $bool = true; } } } } print_r($json);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 36
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 36
Branch analysis from position: 17
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 34
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 34
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 33
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 33
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 33
Branch analysis from position: 33
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 34
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/X7FoM
function name:  (null)
number of ops:  41
compiled vars:  !0 = $jsonProducts, !1 = $jsonData, !2 = $price, !3 = $json, !4 = $bool, !5 = $value, !6 = $key, !7 = $value2, !8 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%0A++%7B%0A++++%22name%22%3A+%22Fluted+Guard+of+the+Moon+Rider%22%2C%0A++++%22icon%22%3A+%22-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KW1Zwwo4NUX4oFJZEHLbXK9QlSPcU_oAlcQk2fVOiSxMfcRlFwIBYYpbaaOA9vxv_MdC8M7tq0xoaOzvb2Z7iJxD8GsJIi0--Up9Sh0A2yr0pvZ22iJdXGdVQ5NUaQpAZGHIGG2g%22%0A++%7D%2C%0A++%7B%0A++++%22name%22%3A+%22Lion+Quiver+of+the+Moon+Rider%22%2C%0A++++%22icon%22%3A+%22-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KW1Zwwo4NUX4oFJZEHLbXK9QlSPcU_oAlcQk2fVOiSxtraRVhmahdbiauwIhFlwb2aImoS7oWwzIPYwqetYeKExm9SsMAg3b7AoNz32QDkqUNtMD2lJdPGbEZgNjYx8IO6%22%0A++%7D%2C%0A++%7B%0A++++%22name%22%3A+%22Lion+Quiver+of+the+Moon+Rider%22%2C%0A++++%22icon%22%3A+%22-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KW1Zwwo4NUX4oFJZEHLbXK9QlSPcU_oAlcQk2fVOiSxtraRVhmahdbiauwIhFlwb2aImoS7oWwzIPYwqetYeKExm9SsMAg3b7AoNz32QDkqUNtMD2lJdPGbEZgNjYx8IO6%22%0A++%7D%0A++%5D'
   18     1        ASSIGN                                                   !1, '%7B%0A++++%22data%22%3A+%5B%0A++++++++%7B%0A++++++++++%22updated_at%22%3A+1576048969000%2C%0A++++++++++%22prices%22%3A+%7B%0A++++++++++++%22last%22%3A+5300%0A++++++++++%7D%2C%0A++++++++++%22name%22%3A+%22Lion+Quiver+of+the+Moon+Rider%22%0A++++++++%7D%2C%0A++++++++%7B%0A++++++++++%22updated_at%22%3A+1576048969000%2C%0A++++++++++%22prices%22%3A+%7B%0A++++++++++++%22last%22%3A+2000.12%0A++++++++++%7D%2C%0A++++++++++%22name%22%3A+%22T-shirts%22%0A++++++++%7D%0A++++%5D%0A%7D'
   37     2        ECHO                                                     '%3Cpre%3E'
   39     3        INIT_FCALL                                               'json_decode'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 1
          6        DO_ICALL                                         $11     
          7        FETCH_DIM_R                                      ~12     $11, 'data'
          8        ASSIGN                                                   !2, ~12
   40     9        INIT_FCALL                                               'json_decode'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 1
         12        DO_ICALL                                         $14     
         13        ASSIGN                                                   !3, $14
   42    14        ASSIGN                                                   !4, <false>
   44    15      > FE_RESET_R                                       $17     !2, ->36
         16    > > FE_FETCH_R                                       ~18     $17, !5, ->36
         17    >   ASSIGN                                                   !6, ~18
   46    18      > FE_RESET_R                                       $20     !3, ->34
         19    > > FE_FETCH_R                                       ~21     $20, !7, ->34
         20    >   ASSIGN                                                   !8, ~21
   47    21        FETCH_DIM_R                                      ~23     !5, 'name'
         22        FETCH_DIM_R                                      ~24     !7, 'name'
         23        IS_IDENTICAL                                             ~23, ~24
         24      > JMPZ                                                     ~25, ->33
   48    25    >   TYPE_CHECK                                  1014          !4
         26      > JMPZ                                                     ~26, ->33
   49    27    >   FETCH_DIM_R                                      ~29     !5, 'prices'
         28        FETCH_DIM_R                                      ~30     ~29, 'last'
         29        FETCH_DIM_W                                      $27     !3, !8
         30        ASSIGN_DIM                                               $27, 'price'
         31        OP_DATA                                                  ~30
   50    32        ASSIGN                                                   !4, <true>
   46    33    > > JMP                                                      ->19
         34    >   FE_FREE                                                  $20
   44    35      > JMP                                                      ->16
         36    >   FE_FREE                                                  $17
   56    37        INIT_FCALL                                               'print_r'
         38        SEND_VAR                                                 !3
         39        DO_ICALL                                                 
         40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
179.2 ms | 1400 KiB | 17 Q