3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = "<?xml version='1.0' encoding='ISO-8859-1'?> <delta> <history> <detail> <id>one</id> <degree> <dname>alpha</dname> <dates> <StartDate> <Year>1998</Year> </StartDate> <EndDate> <Year>2002</Year> </EndDate> </dates> </degree> </detail> <detail> <id>two</id> <degree> <dname>beta</dname> <dates> <StartDate> <Year>2006</Year> </StartDate> <EndDate> <Year>2008</Year> </EndDate> </dates> </degree> </detail> </history> </delta>"; $doc = new DOMDocument; $doc->preserveWhiteSpace = false; $doc->loadXML($xml); $xpath = new DOMXPath($doc); $items = $doc->getElementsByTagName("detail"); $subitemarray = array(); $icounter = 0; foreach ($items as $item) { $query = "//dates"; //xpath of all occurrence of Year $entries = $xpath->query($query, $item); foreach ($entries as $entry) { $startDate = $entry->getElementsByTagName("StartDate")[0]->nodeValue; $endDate = $entry->getElementsByTagName("EndDate")[0]->nodeValue; $dates["startdate"] = $startDate; //extract StartDate $dates["enddate"] = $endDate; //extract EndDate } $subitemarray[$icounter++] = $dates; } var_dump($subitemarray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 51
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 51
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 46
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 46
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 46
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
filename:       /in/7bE9n
function name:  (null)
number of ops:  56
compiled vars:  !0 = $xml, !1 = $doc, !2 = $xpath, !3 = $items, !4 = $subitemarray, !5 = $icounter, !6 = $item, !7 = $query, !8 = $entries, !9 = $entry, !10 = $startDate, !11 = $endDate, !12 = $dates
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%271.0%27+encoding%3D%27ISO-8859-1%27%3F%3E%0A%3Cdelta%3E%0A++++%3Chistory%3E%0A++++++++%3Cdetail%3E%0A++++++++++++%3Cid%3Eone%3C%2Fid%3E%0A++++++++++++%3Cdegree%3E%0A++++++++++++++++%3Cdname%3Ealpha%3C%2Fdname%3E%0A++++++++++++++++%3Cdates%3E%0A++++++++++++++++++++%3CStartDate%3E%0A++++++++++++++++++++++++%3CYear%3E1998%3C%2FYear%3E%0A++++++++++++++++++++%3C%2FStartDate%3E%0A++++++++++++++++++++%3CEndDate%3E%0A++++++++++++++++++++++++%3CYear%3E2002%3C%2FYear%3E%0A++++++++++++++++++++%3C%2FEndDate%3E%0A++++++++++++++++%3C%2Fdates%3E%0A++++++++++++%3C%2Fdegree%3E%0A++++++++%3C%2Fdetail%3E%0A++++++++%3Cdetail%3E%0A++++++++++++%3Cid%3Etwo%3C%2Fid%3E%0A++++++++++++%3Cdegree%3E%0A++++++++++++++++%3Cdname%3Ebeta%3C%2Fdname%3E%0A++++++++++++++++%3Cdates%3E%0A++++++++++++++++++++%3CStartDate%3E%0A++++++++++++++++++++++++%3CYear%3E2006%3C%2FYear%3E%0A++++++++++++++++++++%3C%2FStartDate%3E%0A++++++++++++++++++++%3CEndDate%3E%0A++++++++++++++++++++++++%3CYear%3E2008%3C%2FYear%3E%0A++++++++++++++++++++%3C%2FEndDate%3E%0A++++++++++++++++%3C%2Fdates%3E%0A++++++++++++%3C%2Fdegree%3E%0A++++++++%3C%2Fdetail%3E%0A++++%3C%2Fhistory%3E%0A%3C%2Fdelta%3E'
   36     1        NEW                                              $14     'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $14
   37     4        ASSIGN_OBJ                                               !1, 'preserveWhiteSpace'
          5        OP_DATA                                                  <false>
   38     6        INIT_METHOD_CALL                                         !1, 'loadXML'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
   39     9        NEW                                              $19     'DOMXPath'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !2, $19
   40    13        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         14        SEND_VAL_EX                                              'detail'
         15        DO_FCALL                                      0  $22     
         16        ASSIGN                                                   !3, $22
   41    17        ASSIGN                                                   !4, <array>
   42    18        ASSIGN                                                   !5, 0
   43    19      > FE_RESET_R                                       $26     !3, ->51
         20    > > FE_FETCH_R                                               $26, !6, ->51
   44    21    >   ASSIGN                                                   !7, '%2F%2Fdates'
   45    22        INIT_METHOD_CALL                                         !2, 'query'
         23        SEND_VAR_EX                                              !7
         24        SEND_VAR_EX                                              !6
         25        DO_FCALL                                      0  $28     
         26        ASSIGN                                                   !8, $28
   46    27      > FE_RESET_R                                       $30     !8, ->46
         28    > > FE_FETCH_R                                               $30, !9, ->46
   47    29    >   INIT_METHOD_CALL                                         !9, 'getElementsByTagName'
         30        SEND_VAL_EX                                              'StartDate'
         31        DO_FCALL                                      0  $31     
         32        FETCH_DIM_R                                      ~32     $31, 0
         33        FETCH_OBJ_R                                      ~33     ~32, 'nodeValue'
         34        ASSIGN                                                   !10, ~33
   48    35        INIT_METHOD_CALL                                         !9, 'getElementsByTagName'
         36        SEND_VAL_EX                                              'EndDate'
         37        DO_FCALL                                      0  $35     
         38        FETCH_DIM_R                                      ~36     $35, 0
         39        FETCH_OBJ_R                                      ~37     ~36, 'nodeValue'
         40        ASSIGN                                                   !11, ~37
   49    41        ASSIGN_DIM                                               !12, 'startdate'
         42        OP_DATA                                                  !10
   50    43        ASSIGN_DIM                                               !12, 'enddate'
         44        OP_DATA                                                  !11
   46    45      > JMP                                                      ->28
         46    >   FE_FREE                                                  $30
   52    47        POST_INC                                         ~41     !5
         48        ASSIGN_DIM                                               !4, ~41
         49        OP_DATA                                                  !12
   43    50      > JMP                                                      ->20
         51    >   FE_FREE                                                  $26
   54    52        INIT_FCALL                                               'var_dump'
         53        SEND_VAR                                                 !4
         54        DO_ICALL                                                 
         55      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.8 ms | 1015 KiB | 14 Q