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> <item> <name>C</name> <type>DDD</type> </item> </itemList> </root>"; $xml = new SimpleXMLElement($xml); $res = $xml->xpath('//type[contains(text(), "DDD")]/parent::item/preceding-sibling::item'); $total = count($res); echo "{$res[$total - 1]->name} ({$res[$total - 1]->type})".PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1oYIi
function name:  (null)
number of ops:  24
compiled vars:  !0 = $xml, !1 = $res, !2 = $total
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     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++++++++%3Citem%3E%0A++++++++++++%3Cname%3EC%3C%2Fname%3E%0A++++++++++++%3Ctype%3EDDD%3C%2Ftype%3E%0A++++++++%3C%2Fitem%3E%0A++++%3C%2FitemList%3E%0A%3C%2Froot%3E'
   23     1        NEW                                              $4      'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $4
   25     5        INIT_METHOD_CALL                                         !0, 'xpath'
          6        SEND_VAL_EX                                              '%2F%2Ftype%5Bcontains%28text%28%29%2C+%22DDD%22%29%5D%2Fparent%3A%3Aitem%2Fpreceding-sibling%3A%3Aitem'
          7        DO_FCALL                                      0  $7      
          8        ASSIGN                                                   !1, $7
   26     9        COUNT                                            ~9      !1
         10        ASSIGN                                                   !2, ~9
   27    11        SUB                                              ~11     !2, 1
         12        FETCH_DIM_R                                      ~12     !1, ~11
         13        FETCH_OBJ_R                                      ~13     ~12, 'name'
         14        ROPE_INIT                                     4  ~18     ~13
         15        ROPE_ADD                                      1  ~18     ~18, '+%28'
         16        SUB                                              ~14     !2, 1
         17        FETCH_DIM_R                                      ~15     !1, ~14
         18        FETCH_OBJ_R                                      ~16     ~15, 'type'
         19        ROPE_ADD                                      2  ~18     ~18, ~16
         20        ROPE_END                                      3  ~17     ~18, '%29'
         21        CONCAT                                           ~20     ~17, '%0A'
         22        ECHO                                                     ~20
   28    23      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.95 ms | 1435 KiB | 13 Q