3v4l.org

run code in 300+ PHP versions simultaneously
<?php function xml_to_array($xml,$main_heading = '') { $deXml = simplexml_load_string($xml); $deJson = json_encode($deXml); $xml_array = json_decode($deJson,TRUE); if (! empty($main_heading)) { $returned = $xml_array[$main_heading]; return $returned; } else { return $xml_array; } } $xml = ' <users> <user> <first_name>John</first_name> <last_name>Doe</last_name> <address> <line1>123 Street</line1> <line2>Apt. 9</line2> <city>Chicago</city> </address> </user> <user> <first_name>abc</first_name> <last_name>443</last_name> <address> <line1>777 Street</line1> <line2>Apt. 776</line2> <city>vvv</city> </address> </user> </users>'; $data_array = xml_to_array($xml,'address'); var_dump($data_array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KobiD
function name:  (null)
number of ops:  10
compiled vars:  !0 = $xml, !1 = $data_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, '%0A%3Cusers%3E%0A%3Cuser%3E%0A++++%3Cfirst_name%3EJohn%3C%2Ffirst_name%3E%0A++++%3Clast_name%3EDoe%3C%2Flast_name%3E%0A++++%3Caddress%3E%0A++++++++%3Cline1%3E123+Street%3C%2Fline1%3E%0A++++++++%3Cline2%3EApt.+9%3C%2Fline2%3E%0A++++++++%3Ccity%3EChicago%3C%2Fcity%3E%0A++++%3C%2Faddress%3E%0A%3C%2Fuser%3E%0A%0A%3Cuser%3E%0A++++%3Cfirst_name%3Eabc%3C%2Ffirst_name%3E%0A++++%3Clast_name%3E443%3C%2Flast_name%3E%0A++++%3Caddress%3E%0A++++++++%3Cline1%3E777+Street%3C%2Fline1%3E%0A++++++++%3Cline2%3EApt.+776%3C%2Fline2%3E%0A++++++++%3Ccity%3Evvv%3C%2Fcity%3E%0A++++%3C%2Faddress%3E%0A%3C%2Fuser%3E%0A%3C%2Fusers%3E'
   37     1        INIT_FCALL                                               'xml_to_array'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'address'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   38     6        INIT_FCALL                                               'var_dump'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function xml_to_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 22
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KobiD
function name:  xml_to_array
number of ops:  24
compiled vars:  !0 = $xml, !1 = $main_heading, !2 = $deXml, !3 = $deJson, !4 = $xml_array, !5 = $returned
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
    3     2        INIT_FCALL                                               'simplexml_load_string'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !2, $6
    4     6        INIT_FCALL                                               'json_encode'
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !3, $8
    5    10        INIT_FCALL                                               'json_decode'
         11        SEND_VAR                                                 !3
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $10     
         14        ASSIGN                                                   !4, $10
    6    15        ISSET_ISEMPTY_CV                                 ~12     !1
         16        BOOL_NOT                                         ~13     ~12
         17      > JMPZ                                                     ~13, ->22
    7    18    >   FETCH_DIM_R                                      ~14     !4, !1
         19        ASSIGN                                                   !5, ~14
    8    20      > RETURN                                                   !5
         21*       JMP                                                      ->23
   10    22    > > RETURN                                                   !4
   12    23*     > RETURN                                                   null

End of function xml_to_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.1 ms | 1394 KiB | 22 Q