3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = "<root> <itemList> <item> <name>A</name> <type>AAA</type> </item> <item> <name>B</name> <type>BBB</type> </item> <item> <name>C</name> <type>CCC</type> </item> </itemList> </root>"; $xml = new SimpleXMLElement($xml); $res = $xml->xpath('//type[contains(text(), "BBB")]/parent::item/preceding-sibling::item[1]'); echo "{$res[0]->name} ({$res[0]->type})".PHP_EOL; $res = $xml->xpath('//type[contains(text(), "CCC")]/parent::item/preceding-sibling::item[1]'); echo "{$res[0]->name} ({$res[0]->type})";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kcl38
function name:  (null)
number of ops:  33
compiled vars:  !0 = $xml, !1 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Croot%3E%0A++++%3CitemList%3E%0A++++++++%3Citem%3E%0A++++++++++++%3Cname%3EA%3C%2Fname%3E%0A++++++++++++%3Ctype%3EAAA%3C%2Ftype%3E%0A++++++++%3C%2Fitem%3E%0A++++++++%3Citem%3E%0A++++++++++++%3Cname%3EB%3C%2Fname%3E%0A++++++++++++%3Ctype%3EBBB%3C%2Ftype%3E%0A++++++++%3C%2Fitem%3E%0A++++++++%3Citem%3E%0A++++++++++++%3Cname%3EC%3C%2Fname%3E%0A++++++++++++%3Ctype%3ECCC%3C%2Ftype%3E%0A++++++++%3C%2Fitem%3E%0A++++%3C%2FitemList%3E%0A%3C%2Froot%3E'
   20     1        NEW                                              $3      'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $3
   22     5        INIT_METHOD_CALL                                         !0, 'xpath'
          6        SEND_VAL_EX                                              '%2F%2Ftype%5Bcontains%28text%28%29%2C+%22BBB%22%29%5D%2Fparent%3A%3Aitem%2Fpreceding-sibling%3A%3Aitem%5B1%5D'
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !1, $6
   23     9        FETCH_DIM_R                                      ~8      !1, 0
         10        FETCH_OBJ_R                                      ~9      ~8, 'name'
         11        ROPE_INIT                                     4  ~13     ~9
         12        ROPE_ADD                                      1  ~13     ~13, '+%28'
         13        FETCH_DIM_R                                      ~10     !1, 0
         14        FETCH_OBJ_R                                      ~11     ~10, 'type'
         15        ROPE_ADD                                      2  ~13     ~13, ~11
         16        ROPE_END                                      3  ~12     ~13, '%29'
         17        CONCAT                                           ~15     ~12, '%0A'
         18        ECHO                                                     ~15
   25    19        INIT_METHOD_CALL                                         !0, 'xpath'
         20        SEND_VAL_EX                                              '%2F%2Ftype%5Bcontains%28text%28%29%2C+%22CCC%22%29%5D%2Fparent%3A%3Aitem%2Fpreceding-sibling%3A%3Aitem%5B1%5D'
         21        DO_FCALL                                      0  $16     
         22        ASSIGN                                                   !1, $16
   26    23        FETCH_DIM_R                                      ~18     !1, 0
         24        FETCH_OBJ_R                                      ~19     ~18, 'name'
         25        ROPE_INIT                                     4  ~23     ~19
         26        ROPE_ADD                                      1  ~23     ~23, '+%28'
         27        FETCH_DIM_R                                      ~20     !1, 0
         28        FETCH_OBJ_R                                      ~21     ~20, 'type'
         29        ROPE_ADD                                      2  ~23     ~23, ~21
         30        ROPE_END                                      3  ~22     ~23, '%29'
         31        ECHO                                                     ~22
         32      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.21 ms | 1435 KiB | 13 Q