3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xmlStr = <<<XML <?xml version='1.0' encoding='UTF-8' standalone='yes'?> <root></root> XML; $xml = new \SimpleXMLElement($xmlStr); $xml = assocToXml(['one' => 1, 'two' => ['three' => 3, 'four' => '4']], $xml); var_dump($xml); function assocToXml(array $array, \SimpleXMLElement &$xml) { foreach ($array as $key => $value) { if (!is_array($value)) { if (is_string($key)) { $xml->addChild($key, $value); } } else { $xml->addChild($key); assocToXml($value, $xml->{$key}); } } return $xml; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vobEc
function name:  (null)
number of ops:  14
compiled vars:  !0 = $xmlStr, !1 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%271.0%27+encoding%3D%27UTF-8%27+standalone%3D%27yes%27%3F%3E%0A%3Croot%3E%3C%2Froot%3E'
    7     1        NEW                                              $3      'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $3
    8     5        INIT_FCALL_BY_NAME                                       'assocToXml'
          6        SEND_VAL_EX                                              <array>
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !1, $6
    9    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
   24    13      > RETURN                                                   1

Function assoctoxml:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 25
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 15
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 14
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/vobEc
function name:  assocToXml
number of ops:  28
compiled vars:  !0 = $array, !1 = $xml, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   13     2      > FE_RESET_R                                       $4      !0, ->25
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->25
          4    >   ASSIGN                                                   !3, ~5
   14     5        TYPE_CHECK                                  128  ~7      !2
          6        BOOL_NOT                                         ~8      ~7
          7      > JMPZ                                                     ~8, ->15
   15     8    >   TYPE_CHECK                                   64          !3
          9      > JMPZ                                                     ~9, ->14
   16    10    >   INIT_METHOD_CALL                                         !1, 'addChild'
         11        SEND_VAR_EX                                              !3
         12        SEND_VAR_EX                                              !2
         13        DO_FCALL                                      0          
         14    > > JMP                                                      ->24
   19    15    >   INIT_METHOD_CALL                                         !1, 'addChild'
         16        SEND_VAR_EX                                              !3
         17        DO_FCALL                                      0          
   20    18        INIT_FCALL_BY_NAME                                       'assocToXml'
         19        SEND_VAR_EX                                              !2
         20        CHECK_FUNC_ARG                                           
         21        FETCH_OBJ_FUNC_ARG                               $12     !1, !3
         22        SEND_FUNC_ARG                                            $12
         23        DO_FCALL                                      0          
   13    24    > > JMP                                                      ->3
         25    >   FE_FREE                                                  $4
   23    26      > RETURN                                                   !1
   24    27*     > RETURN                                                   null

End of function assoctoxml

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.44 ms | 1400 KiB | 15 Q