3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = json_decode('[ { "products": [ { "Part ID" : "001", "name" : "Product Name", "category" : "Product Category", "description" : "Product Description", "id" : "111xyz" }, { "Part ID" : "002", "name" : "Product Name 2", "category" : "Product Category 2", "description" : "Product Description 2", "id" : "333xyz" }, { "Part ID" : "003", "name" : "Product Name 3", "category" : "Product Category 3", "description" : "Product Description 3", "id" : "444xyz" }, { "Part ID" : "004", "name" : "Product Name 4", "category" : "Product Category", "description" : "Product Description", "id" : "666xyz", "features_img_id":["f1","f2","f3"] }] }, { "assets": [ { "File Name" : "Some file name", "url" : "www.123.com/x.jpg", "id" : "111xyz" }, { "File Name" : "Feature 1 file", "url" : "www.123.com/f1.jpg", "id" : "f1" }, { "File Name" : "Feature 2 file", "url" : "www.123.com/f2.jpg", "id" : "f2" }, { "File Name" : "Feature 2 file", "url" : "www.123.com/f3.jpg", "id" : "f3" }] } ]'); $map = array_column($array[1]->assets, 'url', 'id'); foreach ($array[0]->products as $obj) { if (isset($map[$obj->id])) { $obj->url = $map[$obj->id]; } foreach ($obj->features_img_id ?? [] as $imgId) { if (isset($map[$imgId])) { $obj->feature_img_url[] = $map[$imgId]; } } unset($obj->id, $obj->features_img_id); } var_export($array[0]->products);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 39
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 39
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 35
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 34
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 34
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 35
Branch analysis from position: 23
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/FlNeB
function name:  (null)
number of ops:  46
compiled vars:  !0 = $array, !1 = $map, !2 = $obj, !3 = $imgId
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'json_decode'
          1        SEND_VAL                                                     '%5B%0A++++++++++++%7B%0A++++++++++++++++%22products%22%3A+%5B%0A++++++++++++++++++++%7B%0A++++++++++++++++++++++++%22Part+ID%22+%3A+%22001%22%2C%0A++++++++++++++++++++++++%22name%22+%3A+%22Product+Name%22%2C%0A++++++++++++++++++++++++%22category%22+%3A+%22Product+Category%22%2C%0A++++++++++++++++++++++++%22description%22+%3A+%22Product+Description%22%2C%0A++++++++++++++++++++++++%22id%22+%3A+%22111xyz%22%0A++++++++++++++++++++%7D%2C%0A++++++++++++++++++++%7B%0A++++++++++++++++++++++++%22Part+ID%22+%3A+%22002%22%2C%0A++++++++++++++++++++++++%22name%22+%3A+%22Product+Name+2%22%2C%0A++++++++++++++++++++++++%22category%22+%3A+%22Product+Category+2%22%2C%0A++++++++++++++++++++++++%22description%22+%3A+%22Product+Description+2%22%2C%0A++++++++++++++++++++++++%22id%22+%3A+%22333xyz%22%0A++++++++++++++++++++%7D%2C%0A++++++++++++++++++++%7B%0A++++++++++++++++++++++++%22Part+ID%22+%3A+%22003%22%2C%0A++++++++++++++++++++++++%22name%22+%3A+%22Product+Name+3%22%2C%0A++++++++++++++++++++++++%22category%22+%3A+%22Product+Category+3%22%2C%0A++++++++++++++++++++++++%22description%22+%3A+%22Product+Description+3%22%2C%0A++++++++++++++++++++++++%22id%22+%3A+%22444xyz%22%0A++++++++++++++++++++%7D%2C++%0A++++++++++++++++++++%7B%0A++++++++++++++++++++++++%22Part+ID%22+%3A+%22004%22%2C%0A++++++++++++++++++++++++%22name%22+%3A+%22Product+Name+4%22%2C%0A++++++++++++++++++++++++%22category%22+%3A+%22Product+Category%22%2C%0A++++++++++++++++++++++++%22description%22+%3A+%22Product+Description%22%2C%0A++++++++++++++++++++++++%22id%22+%3A+%22666xyz%22%2C%0A++++++++++++++++++++++++%22features_img_id%22%3A%5B%22f1%22%2C%22f2%22%2C%22f3%22%5D%0A++++++++++++++++++++%7D%5D%0A++++++++++++++++%7D%2C%0A++++++++++++++++%7B%0A++++++++++++++++%22assets%22%3A+%5B%0A++++++++++++++++++++%7B%0A++++++++++++++++++++++++%22File+Name%22+%3A+%22Some+file+name%22%2C%0A++++++++++++++++++++++++%22url%22+%3A+%22www.123.com%2Fx.jpg%22%2C%0A++++++++++++++++++++++++%22id%22+%3A+%22111xyz%22%0A++++++++++++++++++++%7D%2C%0A++++++++++++++++++++%7B%0A+++++++++++++++++++++++++%22File+Name%22+%3A+%22Feature+1+file%22%2C%0A++++++++++++++++++++++++%22url%22+%3A+%22www.123.com%2Ff1.jpg%22%2C%0A++++++++++++++++++++++++%22id%22+%3A+%22f1%22%0A++++++++++++++++++++%7D%2C%0A++++++++++++++++++++%7B%0A+++++++++++++++++++++++++%22File+Name%22+%3A+%22Feature+2+file%22%2C%0A++++++++++++++++++++++++%22url%22+%3A+%22www.123.com%2Ff2.jpg%22%2C%0A++++++++++++++++++++++++%22id%22+%3A+%22f2%22%0A++++++++++++++++++++%7D%2C%0A++++++++++++++++++++%7B%0A+++++++++++++++++++++++++%22File+Name%22+%3A+%22Feature+2+file%22%2C%0A++++++++++++++++++++++++%22url%22+%3A+%22www.123.com%2Ff3.jpg%22%2C%0A++++++++++++++++++++++++%22id%22+%3A+%22f3%22%0A++++++++++++++++++++%7D%5D%0A++++++++++++%7D%0A%5D'
          2        DO_ICALL                                             $4      
          3        ASSIGN                                                       !0, $4
   61     4        INIT_FCALL                                                   'array_column'
          5        FETCH_DIM_R                                          ~6      !0, 1
          6        FETCH_OBJ_R                                          ~7      ~6, 'assets'
          7        SEND_VAL                                                     ~7
          8        SEND_VAL                                                     'url'
          9        SEND_VAL                                                     'id'
         10        DO_ICALL                                             $8      
         11        ASSIGN                                                       !1, $8
   63    12        FETCH_DIM_R                                          ~10     !0, 0
         13        FETCH_OBJ_R                                          ~11     ~10, 'products'
         14      > FE_RESET_R                                           $12     ~11, ->39
         15    > > FE_FETCH_R                                                   $12, !2, ->39
   64    16    >   FETCH_OBJ_R                                          ~13     !2, 'id'
         17        ISSET_ISEMPTY_DIM_OBJ                             0          !1, ~13
         18      > JMPZ                                                         ~14, ->23
   65    19    >   FETCH_OBJ_R                                          ~16     !2, 'id'
         20        FETCH_DIM_R                                          ~17     !1, ~16
         21        ASSIGN_OBJ                                                   !2, 'url'
         22        OP_DATA                                                      ~17
   67    23    >   FETCH_OBJ_IS                                         ~18     !2, 'features_img_id'
         24        COALESCE                                             ~19     ~18
         25        QM_ASSIGN                                            ~19     <array>
         26      > FE_RESET_R                                           $20     ~19, ->35
         27    > > FE_FETCH_R                                                   $20, !3, ->35
   68    28    >   ISSET_ISEMPTY_DIM_OBJ                             0          !1, !3
         29      > JMPZ                                                         ~21, ->34
   69    30    >   FETCH_DIM_R                                          ~24     !1, !3
         31        FETCH_OBJ_W                                          $22     !2, 'feature_img_url'
         32        ASSIGN_DIM                                                   $22
         33        OP_DATA                                                      ~24
   67    34    > > JMP                                                          ->27
         35    >   FE_FREE                                                      $20
   72    36        UNSET_OBJ                                                    !2, 'id'
         37        UNSET_OBJ                                                    !2, 'features_img_id'
   63    38      > JMP                                                          ->15
         39    >   FE_FREE                                                      $12
   74    40        INIT_FCALL                                                   'var_export'
         41        FETCH_DIM_R                                          ~25     !0, 0
         42        FETCH_OBJ_R                                          ~26     ~25, 'products'
         43        SEND_VAL                                                     ~26
         44        DO_ICALL                                                     
         45      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
230.96 ms | 2036 KiB | 16 Q