3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml_str = '<?xml version="1.0" encoding="UTF-8" standalone="no"?> <ExpResponse engineVersion="201404_02a" status="OK" xml:space="preserve"> <MethodReturn> <TrainInformation displayName="普通" driveComment="平日運転" guideComment="" traffic="1" type="Train"> <StopStationList> <StopStation areaCode="16" code="29181" departureTime="1810" getOff="False" getOn="False" kenCode="26" name="国際会館"/> <StopStation areaCode="16" arraivalTime="1812" arrivalTime="1812" code="29182" departureTime="1812" getOff="False" getOn="False" kenCode="26" name="松ケ崎(京都府)"/> <StopStation areaCode="16" arraivalTime="1814" arrivalTime="1814" code="25641" departureTime="1814" getOff="False" getOn="False" kenCode="26" name="北山(京都府)"/> <StopStation areaCode="16" arraivalTime="1816" arrivalTime="1816" code="25639" departureTime="1816" getOff="False" getOn="False" kenCode="26" name="北大路"/> <StopStation areaCode="16" arraivalTime="1818" arrivalTime="1818" code="25656" departureTime="1818" getOff="False" getOn="False" kenCode="26" name="鞍馬口"/> <StopStation areaCode="16" arraivalTime="1819" arrivalTime="1819" code="25598" departureTime="1820" getOff="False" getOn="False" kenCode="26" name="今出川"/> <StopStation areaCode="16" arraivalTime="1822" arrivalTime="1822" code="25767" departureTime="1822" getOff="False" getOn="False" kenCode="26" name="丸太町(京都市営)"/> <StopStation areaCode="16" arraivalTime="1824" arrivalTime="1824" code="25607" departureTime="1824" getOff="False" getOn="False" kenCode="26" name="烏丸御池"/> <StopStation areaCode="16" arraivalTime="1825" arrivalTime="1825" code="25681" departureTime="1826" getOff="False" getOn="False" kenCode="26" name="四条(京都市営)"/> <StopStation areaCode="16" arraivalTime="1827" arrivalTime="1827" code="25670" departureTime="1828" getOff="False" getOn="False" kenCode="26" name="五条(京都市営)"/> <StopStation areaCode="16" arraivalTime="1829" arrivalTime="1829" code="25647" departureTime="1830" getOff="False" getOn="False" kenCode="26" name="京都"/> <StopStation areaCode="16" arraivalTime="1831" arrivalTime="1831" code="25651" departureTime="1831" getOff="False" getOn="False" kenCode="26" name="九条(京都府)"/> <StopStation areaCode="16" arraivalTime="1832" arrivalTime="1832" code="25694" departureTime="1833" getOff="False" getOn="False" kenCode="26" name="十条(京都市営)"/> <StopStation areaCode="16" arraivalTime="1834" arrivalTime="1834" code="25650" departureTime="1835" getOff="False" getOn="False" kenCode="26" name="くいな橋"/> <StopStation areaCode="16" arraivalTime="1836" arrivalTime="1836" code="25701" departureTime="1838" getOff="False" getOn="False" kenCode="26" name="竹田(京都府)"/> <StopStation areaCode="16" arraivalTime="1840" arrivalTime="1840" code="25752" departureTime="1840" getOff="False" getOn="False" kenCode="26" name="伏見(京都府)"/> <StopStation areaCode="16" arraivalTime="1842" arrivalTime="1842" code="25648" departureTime="1842" getOff="False" getOn="False" kenCode="26" name="近鉄丹波橋"/> <StopStation areaCode="16" arraivalTime="1843" arrivalTime="1843" code="25780" departureTime="1844" getOff="False" getOn="False" kenCode="26" name="桃山御陵前"/> <StopStation areaCode="16" arraivalTime="1847" arrivalTime="1847" code="25776" departureTime="1847" getOff="False" getOn="False" kenCode="26" name="向島"/> <StopStation areaCode="16" arraivalTime="1850" arrivalTime="1850" code="25618" departureTime="1851" getOff="False" getOn="False" kenCode="26" name="小倉(京都府)"/> <StopStation areaCode="16" arraivalTime="1852" arrivalTime="1852" code="25594" departureTime="1852" getOff="False" getOn="False" kenCode="26" name="伊勢田"/> <StopStation areaCode="16" arraivalTime="1854" arrivalTime="1854" code="25614" departureTime="1859" getOff="False" getOn="False" kenCode="26" name="大久保(京都府)"/> <StopStation areaCode="16" arraivalTime="1900" arrivalTime="1900" code="25653" departureTime="1901" getOff="False" getOn="False" kenCode="26" name="久津川"/> <StopStation areaCode="16" arraivalTime="1902" arrivalTime="1902" code="25716" departureTime="1902" getOff="False" getOn="False" kenCode="26" name="寺田(京都府)"/> <StopStation areaCode="16" arraivalTime="1904" arrivalTime="1904" code="25722" departureTime="1904" getOff="False" getOn="False" kenCode="26" name="富野荘"/> <StopStation areaCode="16" arraivalTime="1907" arrivalTime="1907" code="25690" getOff="False" getOn="False" kenCode="26" name="新田辺"/> </StopStationList> </TrainInformation> </MethodReturn> </ExpResponse>'; $xml = simplexml_load_string($xml_str); $result = xml_to_array($xml); // print_r($result); echo json_encode($result, JSON_PRETTY_PRINT); function xml_to_array($xml) { $attributes = array(); $namespaces = $xml->getNameSpaces(true); if (count($namespaces) > 0) { foreach ($namespaces as $ns_key => $ns_val) { foreach ($xml->attributes($ns_val) as $key => $val) { $attributes[$ns_key.":".$key] = (string)$val; } } } foreach ($xml->attributes() as $key => $val) { $attributes[$key] = (string)$val; } $is_single = (count($xml->children()) === 1); foreach ($xml->children() as $key => $val) { $res = xml_to_array($val); if ($is_single) { $attributes[$key] = $res; } elseif (array_key_exists($key, $attributes)) { array_push($attributes[$key], $res); } else { $attributes[$key] = array($res); } } return $attributes; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e9Uj2
function name:  (null)
number of ops:  15
compiled vars:  !0 = $xml_str, !1 = $xml, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22+standalone%3D%22no%22%3F%3E%0A%3CExpResponse+engineVersion%3D%22201404_02a%22+status%3D%22OK%22+xml%3Aspace%3D%22preserve%22%3E%0A%3CMethodReturn%3E%0A%3CTrainInformation+displayName%3D%22%E6%99%AE%E9%80%9A%22+driveComment%3D%22%E5%B9%B3%E6%97%A5%E9%81%8B%E8%BB%A2%22+guideComment%3D%22%22+traffic%3D%221%22+type%3D%22Train%22%3E%0A%3CStopStationList%3E%0A%3CStopStation+areaCode%3D%2216%22+code%3D%2229181%22+departureTime%3D%221810%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E5%9B%BD%E9%9A%9B%E4%BC%9A%E9%A4%A8%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221812%22+arrivalTime%3D%221812%22+code%3D%2229182%22+departureTime%3D%221812%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E6%9D%BE%E3%82%B1%E5%B4%8E%28%E4%BA%AC%E9%83%BD%E5%BA%9C%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221814%22+arrivalTime%3D%221814%22+code%3D%2225641%22+departureTime%3D%221814%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E5%8C%97%E5%B1%B1%28%E4%BA%AC%E9%83%BD%E5%BA%9C%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221816%22+arrivalTime%3D%221816%22+code%3D%2225639%22+departureTime%3D%221816%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E5%8C%97%E5%A4%A7%E8%B7%AF%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221818%22+arrivalTime%3D%221818%22+code%3D%2225656%22+departureTime%3D%221818%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E9%9E%8D%E9%A6%AC%E5%8F%A3%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221819%22+arrivalTime%3D%221819%22+code%3D%2225598%22+departureTime%3D%221820%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E4%BB%8A%E5%87%BA%E5%B7%9D%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221822%22+arrivalTime%3D%221822%22+code%3D%2225767%22+departureTime%3D%221822%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E4%B8%B8%E5%A4%AA%E7%94%BA%28%E4%BA%AC%E9%83%BD%E5%B8%82%E5%96%B6%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221824%22+arrivalTime%3D%221824%22+code%3D%2225607%22+departureTime%3D%221824%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E7%83%8F%E4%B8%B8%E5%BE%A1%E6%B1%A0%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221825%22+arrivalTime%3D%221825%22+code%3D%2225681%22+departureTime%3D%221826%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E5%9B%9B%E6%9D%A1%28%E4%BA%AC%E9%83%BD%E5%B8%82%E5%96%B6%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221827%22+arrivalTime%3D%221827%22+code%3D%2225670%22+departureTime%3D%221828%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E4%BA%94%E6%9D%A1%28%E4%BA%AC%E9%83%BD%E5%B8%82%E5%96%B6%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221829%22+arrivalTime%3D%221829%22+code%3D%2225647%22+departureTime%3D%221830%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E4%BA%AC%E9%83%BD%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221831%22+arrivalTime%3D%221831%22+code%3D%2225651%22+departureTime%3D%221831%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E4%B9%9D%E6%9D%A1%28%E4%BA%AC%E9%83%BD%E5%BA%9C%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221832%22+arrivalTime%3D%221832%22+code%3D%2225694%22+departureTime%3D%221833%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E5%8D%81%E6%9D%A1%28%E4%BA%AC%E9%83%BD%E5%B8%82%E5%96%B6%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221834%22+arrivalTime%3D%221834%22+code%3D%2225650%22+departureTime%3D%221835%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E3%81%8F%E3%81%84%E3%81%AA%E6%A9%8B%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221836%22+arrivalTime%3D%221836%22+code%3D%2225701%22+departureTime%3D%221838%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E7%AB%B9%E7%94%B0%28%E4%BA%AC%E9%83%BD%E5%BA%9C%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221840%22+arrivalTime%3D%221840%22+code%3D%2225752%22+departureTime%3D%221840%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E4%BC%8F%E8%A6%8B%28%E4%BA%AC%E9%83%BD%E5%BA%9C%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221842%22+arrivalTime%3D%221842%22+code%3D%2225648%22+departureTime%3D%221842%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E8%BF%91%E9%89%84%E4%B8%B9%E6%B3%A2%E6%A9%8B%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221843%22+arrivalTime%3D%221843%22+code%3D%2225780%22+departureTime%3D%221844%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E6%A1%83%E5%B1%B1%E5%BE%A1%E9%99%B5%E5%89%8D%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221847%22+arrivalTime%3D%221847%22+code%3D%2225776%22+departureTime%3D%221847%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E5%90%91%E5%B3%B6%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221850%22+arrivalTime%3D%221850%22+code%3D%2225618%22+departureTime%3D%221851%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E5%B0%8F%E5%80%89%28%E4%BA%AC%E9%83%BD%E5%BA%9C%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221852%22+arrivalTime%3D%221852%22+code%3D%2225594%22+departureTime%3D%221852%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E4%BC%8A%E5%8B%A2%E7%94%B0%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221854%22+arrivalTime%3D%221854%22+code%3D%2225614%22+departureTime%3D%221859%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E5%A4%A7%E4%B9%85%E4%BF%9D%28%E4%BA%AC%E9%83%BD%E5%BA%9C%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221900%22+arrivalTime%3D%221900%22+code%3D%2225653%22+departureTime%3D%221901%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E4%B9%85%E6%B4%A5%E5%B7%9D%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221902%22+arrivalTime%3D%221902%22+code%3D%2225716%22+departureTime%3D%221902%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E5%AF%BA%E7%94%B0%28%E4%BA%AC%E9%83%BD%E5%BA%9C%29%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221904%22+arrivalTime%3D%221904%22+code%3D%2225722%22+departureTime%3D%221904%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E5%AF%8C%E9%87%8E%E8%8D%98%22%2F%3E%0A%3CStopStation+areaCode%3D%2216%22+arraivalTime%3D%221907%22+arrivalTime%3D%221907%22+code%3D%2225690%22+getOff%3D%22False%22+getOn%3D%22False%22+kenCode%3D%2226%22+name%3D%22%E6%96%B0%E7%94%B0%E8%BE%BA%22%2F%3E%0A%3C%2FStopStationList%3E%0A%3C%2FTrainInformation%3E%0A%3C%2FMethodReturn%3E%0A%3C%2FExpResponse%3E'
   40     1        INIT_FCALL                                               'simplexml_load_string'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $4      
          4        ASSIGN                                                   !1, $4
   42     5        INIT_FCALL_BY_NAME                                       'xml_to_array'
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !2, $6
   45     9        INIT_FCALL                                               'json_encode'
         10        SEND_VAR                                                 !2
         11        SEND_VAL                                                 128
         12        DO_ICALL                                         $8      
         13        ECHO                                                     $8
   77    14      > RETURN                                                   1

Function xml_to_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 27
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 26
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 26
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 24
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 24
Branch analysis from position: 26
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 36
2 jumps found. (Code = 77) Position 1 = 45, Position 2 = 67
Branch analysis from position: 45
2 jumps found. (Code = 78) Position 1 = 46, Position 2 = 67
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 55
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 63
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
Branch analysis from position: 36
Branch analysis from position: 26
Branch analysis from position: 27
filename:       /in/e9Uj2
function name:  xml_to_array
number of ops:  70
compiled vars:  !0 = $xml, !1 = $attributes, !2 = $namespaces, !3 = $ns_val, !4 = $ns_key, !5 = $val, !6 = $key, !7 = $is_single, !8 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   49     1        ASSIGN                                                   !1, <array>
   51     2        INIT_METHOD_CALL                                         !0, 'getNameSpaces'
          3        SEND_VAL_EX                                              <true>
          4        DO_FCALL                                      0  $10     
          5        ASSIGN                                                   !2, $10
   52     6        COUNT                                            ~12     !2
          7        IS_SMALLER                                               0, ~12
          8      > JMPZ                                                     ~13, ->27
   53     9    > > FE_RESET_R                                       $14     !2, ->26
         10    > > FE_FETCH_R                                       ~15     $14, !3, ->26
         11    >   ASSIGN                                                   !4, ~15
   54    12        INIT_METHOD_CALL                                         !0, 'attributes'
         13        SEND_VAR_EX                                              !3
         14        DO_FCALL                                      0  $17     
         15      > FE_RESET_R                                       $18     $17, ->24
         16    > > FE_FETCH_R                                       ~19     $18, !5, ->24
         17    >   ASSIGN                                                   !6, ~19
   55    18        CONCAT                                           ~21     !4, '%3A'
         19        CONCAT                                           ~22     ~21, !6
         20        CAST                                          6  ~24     !5
         21        ASSIGN_DIM                                               !1, ~22
         22        OP_DATA                                                  ~24
   54    23      > JMP                                                      ->16
         24    >   FE_FREE                                                  $18
   53    25      > JMP                                                      ->10
         26    >   FE_FREE                                                  $14
   60    27    >   INIT_METHOD_CALL                                         !0, 'attributes'
         28        DO_FCALL                                      0  $25     
         29      > FE_RESET_R                                       $26     $25, ->36
         30    > > FE_FETCH_R                                       ~27     $26, !5, ->36
         31    >   ASSIGN                                                   !6, ~27
   61    32        CAST                                          6  ~30     !5
         33        ASSIGN_DIM                                               !1, !6
         34        OP_DATA                                                  ~30
   60    35      > JMP                                                      ->30
         36    >   FE_FREE                                                  $26
   64    37        INIT_METHOD_CALL                                         !0, 'children'
         38        DO_FCALL                                      0  $31     
         39        COUNT                                            ~32     $31
         40        IS_IDENTICAL                                     ~33     ~32, 1
         41        ASSIGN                                                   !7, ~33
   65    42        INIT_METHOD_CALL                                         !0, 'children'
         43        DO_FCALL                                      0  $35     
         44      > FE_RESET_R                                       $36     $35, ->67
         45    > > FE_FETCH_R                                       ~37     $36, !5, ->67
         46    >   ASSIGN                                                   !6, ~37
   66    47        INIT_FCALL_BY_NAME                                       'xml_to_array'
         48        SEND_VAR_EX                                              !5
         49        DO_FCALL                                      0  $39     
         50        ASSIGN                                                   !8, $39
   67    51      > JMPZ                                                     !7, ->55
   68    52    >   ASSIGN_DIM                                               !1, !6
         53        OP_DATA                                                  !8
         54      > JMP                                                      ->66
   69    55    >   ARRAY_KEY_EXISTS                                         !6, !1
         56      > JMPZ                                                     ~42, ->63
   70    57    >   INIT_FCALL                                               'array_push'
         58        FETCH_DIM_W                                      $43     !1, !6
         59        SEND_REF                                                 $43
         60        SEND_VAR                                                 !8
         61        DO_ICALL                                                 
         62      > JMP                                                      ->66
   72    63    >   INIT_ARRAY                                       ~46     !8
         64        ASSIGN_DIM                                               !1, !6
         65        OP_DATA                                                  ~46
   65    66    > > JMP                                                      ->45
         67    >   FE_FREE                                                  $36
   76    68      > RETURN                                                   !1
   77    69*     > RETURN                                                   null

End of function xml_to_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.19 ms | 1404 KiB | 19 Q