3v4l.org

run code in 500+ PHP versions simultaneously
<?php function array_to_xml( $data, &$xml_data ) { foreach( $data as $key => $value ) { foreach($value as $innerkey => $innervalue) { $v = $innervalue['@value']; $t = ""; if(isset($innervalue['@attributes']['typ'])) { $t = $innervalue['@attributes']['typ']; } $kontakt = $xml_data->addChild('kontakt', $v); $kontakt->addAttribute('typ', $t); } } } $data = array("kontakt"=>[ 1=>[ '@value' => 'abc@abc.pl', '@attributes' => ['typ' => 'email'], ], 2=>[ '@value' => '3123453141', '@attributes' => ['typ' => 'telefon'], ], ] ); $xml_data = new SimpleXMLElement('<test></test>') ; array_to_xml($data,$xml_data); echo $xml_data->asXML();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qo9uaU
function name:  (null)
number of ops:  13
compiled vars:  !0 = $data, !1 = $xml_data
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                       !0, <array>
   28     1        NEW                                                  $3      'SimpleXMLElement'
          2        SEND_VAL_EX                                                  '%3Ctest%3E%3C%2Ftest%3E'
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !1, $3
   29     5        INIT_FCALL                                                   'array_to_xml'
          6        SEND_VAR                                                     !0
          7        SEND_REF                                                     !1
          8        DO_FCALL                                          0          
   30     9        INIT_METHOD_CALL                                             !1, 'asXML'
         10        DO_FCALL                                          0  $7      
         11        ECHO                                                         $7
         12      > RETURN                                                       1

Function array_to_xml:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 29
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 29
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 27
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 27
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 17
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 17
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 27
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/Qo9uaU
function name:  array_to_xml
number of ops:  31
compiled vars:  !0 = $data, !1 = $xml_data, !2 = $value, !3 = $key, !4 = $innervalue, !5 = $innerkey, !6 = $v, !7 = $t, !8 = $kontakt
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    4     2      > FE_RESET_R                                           $9      !0, ->29
          3    > > FE_FETCH_R                                           ~10     $9, !2, ->29
          4    >   ASSIGN                                                       !3, ~10
    5     5      > FE_RESET_R                                           $12     !2, ->27
          6    > > FE_FETCH_R                                           ~13     $12, !4, ->27
          7    >   ASSIGN                                                       !5, ~13
    6     8        FETCH_DIM_R                                          ~15     !4, '%40value'
          9        ASSIGN                                                       !6, ~15
    7    10        ASSIGN                                                       !7, ''
    8    11        FETCH_DIM_IS                                         ~18     !4, '%40attributes'
         12        ISSET_ISEMPTY_DIM_OBJ                             0          ~18, 'typ'
         13      > JMPZ                                                         ~19, ->17
    9    14    >   FETCH_DIM_R                                          ~20     !4, '%40attributes'
         15        FETCH_DIM_R                                          ~21     ~20, 'typ'
         16        ASSIGN                                                       !7, ~21
   11    17    >   INIT_METHOD_CALL                                             !1, 'addChild'
         18        SEND_VAL_EX                                                  'kontakt'
         19        SEND_VAR_EX                                                  !6
         20        DO_FCALL                                          0  $23     
         21        ASSIGN                                                       !8, $23
   12    22        INIT_METHOD_CALL                                             !8, 'addAttribute'
         23        SEND_VAL_EX                                                  'typ'
         24        SEND_VAR_EX                                                  !7
         25        DO_FCALL                                          0          
    5    26      > JMP                                                          ->6
         27    >   FE_FREE                                                      $12
    4    28      > JMP                                                          ->3
         29    >   FE_FREE                                                      $9
   15    30      > RETURN                                                       null

End of function array_to_xml

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
130.31 ms | 1500 KiB | 14 Q