3v4l.org

run code in 500+ PHP versions simultaneously
<?php $xml = '<products> <group> <product id="853" symbol="XYZ123" stock="73"></product> <product id="941" symbol="ERX412" stock="57"></product> <product id="1960" symbol="UIX981" stock="21"></product> </group> </products>'; $ids = [853, 1960]; $array = json_decode(json_encode((array)simplexml_load_string($xml)),true); foreach($array['group']['product'] as $v){ $cur = $v['@attributes']['id']; $stock = $v['@attributes']['stock']; in_array($cur, $ids) ? ($res[$cur] = $stock) : ''; } print_r($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 33
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 33
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/5PZYp
function name:  (null)
number of ops:  38
compiled vars:  !0 = $xml, !1 = $ids, !2 = $array, !3 = $v, !4 = $cur, !5 = $stock, !6 = $res
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, '%3Cproducts%3E%0A++++%3Cgroup%3E%0A++++++++%3Cproduct+id%3D%22853%22+symbol%3D%22XYZ123%22+stock%3D%2273%22%3E%3C%2Fproduct%3E%0A++++++++%3Cproduct+id%3D%22941%22+symbol%3D%22ERX412%22+stock%3D%2257%22%3E%3C%2Fproduct%3E%0A++++++++%3Cproduct+id%3D%221960%22+symbol%3D%22UIX981%22+stock%3D%2221%22%3E%3C%2Fproduct%3E%0A++++%3C%2Fgroup%3E%0A%3C%2Fproducts%3E'
    9     1        ASSIGN                                                       !1, <array>
   10     2        INIT_FCALL                                                   'json_decode'
          3        INIT_FCALL                                                   'json_encode'
          4        INIT_FCALL                                                   'simplexml_load_string'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $9      
          7        CAST                                              7  ~10     $9
          8        SEND_VAL                                                     ~10
          9        DO_ICALL                                             $11     
         10        SEND_VAR                                                     $11
         11        SEND_VAL                                                     <true>
         12        DO_ICALL                                             $12     
         13        ASSIGN                                                       !2, $12
   11    14        FETCH_DIM_R                                          ~14     !2, 'group'
         15        FETCH_DIM_R                                          ~15     ~14, 'product'
         16      > FE_RESET_R                                           $16     ~15, ->33
         17    > > FE_FETCH_R                                                   $16, !3, ->33
   12    18    >   FETCH_DIM_R                                          ~17     !3, '%40attributes'
         19        FETCH_DIM_R                                          ~18     ~17, 'id'
         20        ASSIGN                                                       !4, ~18
   13    21        FETCH_DIM_R                                          ~20     !3, '%40attributes'
         22        FETCH_DIM_R                                          ~21     ~20, 'stock'
         23        ASSIGN                                                       !5, ~21
   14    24        FRAMELESS_ICALL_2                in_array            ~23     !4, !1
         25      > JMPZ                                                         ~23, ->30
         26    >   ASSIGN_DIM                                           ~24     !6, !4
         27        OP_DATA                                                      !5
         28        QM_ASSIGN                                            ~25     ~24
         29      > JMP                                                          ->31
         30    >   QM_ASSIGN                                            ~25     ''
         31    >   FREE                                                         ~25
   11    32      > JMP                                                          ->17
         33    >   FE_FREE                                                      $16
   16    34        INIT_FCALL                                                   'print_r'
         35        SEND_VAR                                                     !6
         36        DO_ICALL                                                     
         37      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
173.9 ms | 2336 KiB | 17 Q