3v4l.org

run code in 300+ PHP versions simultaneously
<?php $multiple = [ 'Mobiles' => [ 'MobileNo' => ['123', '456'] ] ]; $single = [ 'Mobiles' => [ 'MobileNo' => '123' ] ]; class convert{ public function arrayToXml($array, $xml) { foreach ($array as $key => $value) { if (is_array($value)) { self::arrayToXml($value, $xml->addChild($key)); } else { if (is_numeric($key)) { $xml->addChild(preg_replace('/s$/', '', $xml->getName()), $value); } else { $xml->addChild($key, $value); } } } } } $xml = new \SimpleXMLElement('<Msg />'); $array = [ 'JobId' => 77]; $i = 0; foreach ($multiple['Mobiles'] as $pNumber) { foreach($pNumber as $mobile ){ $i++; $array[$i]['SubmitResult'] = [ 'MobileNo' => $mobile, 'StatusId' => 0000, 'StatusText' =>'Success: Message submitted successfully', ]; } } //print_r($array); $convert = new convert(); $convert->arrayToXml($array, $xml); var_dump($xml->asXML());
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 23
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 23
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 21
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 21
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/9e7XR
function name:  (null)
number of ops:  37
compiled vars:  !0 = $multiple, !1 = $single, !2 = $xml, !3 = $array, !4 = $i, !5 = $pNumber, !6 = $mobile, !7 = $convert
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   31     2        NEW                                              $10     'SimpleXMLElement'
          3        SEND_VAL_EX                                              '%3CMsg+%2F%3E'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $10
   32     6        ASSIGN                                                   !3, <array>
   34     7        ASSIGN                                                   !4, 0
   35     8        FETCH_DIM_R                                      ~15     !0, 'Mobiles'
          9      > FE_RESET_R                                       $16     ~15, ->23
         10    > > FE_FETCH_R                                               $16, !5, ->23
   36    11    > > FE_RESET_R                                       $17     !5, ->21
         12    > > FE_FETCH_R                                               $17, !6, ->21
   37    13    >   PRE_INC                                                  !4
   39    14        INIT_ARRAY                                       ~21     !6, 'MobileNo'
   40    15        ADD_ARRAY_ELEMENT                                ~21     0, 'StatusId'
   41    16        ADD_ARRAY_ELEMENT                                ~21     'Success%3A+Message+submitted+successfully', 'StatusText'
   38    17        FETCH_DIM_W                                      $19     !3, !4
         18        ASSIGN_DIM                                               $19, 'SubmitResult'
   41    19        OP_DATA                                                  ~21
   36    20      > JMP                                                      ->12
         21    >   FE_FREE                                                  $17
   35    22      > JMP                                                      ->10
         23    >   FE_FREE                                                  $16
   48    24        NEW                                              $22     'convert'
         25        DO_FCALL                                      0          
         26        ASSIGN                                                   !7, $22
   49    27        INIT_METHOD_CALL                                         !7, 'arrayToXml'
         28        SEND_VAR_EX                                              !3
         29        SEND_VAR_EX                                              !2
         30        DO_FCALL                                      0          
   51    31        INIT_FCALL                                               'var_dump'
         32        INIT_METHOD_CALL                                         !2, 'asXML'
         33        DO_FCALL                                      0  $26     
         34        SEND_VAR                                                 $26
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Class convert:
Function arraytoxml:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 36
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 36
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 31
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/9e7XR
function name:  arrayToXml
number of ops:  38
compiled vars:  !0 = $array, !1 = $xml, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   16     2      > FE_RESET_R                                       $4      !0, ->36
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->36
          4    >   ASSIGN                                                   !3, ~5
   17     5        TYPE_CHECK                                  128          !2
          6      > JMPZ                                                     ~7, ->15
   18     7    >   INIT_STATIC_METHOD_CALL                                  'arrayToXml'
          8        SEND_VAR                                                 !2
          9        INIT_METHOD_CALL                                         !1, 'addChild'
         10        SEND_VAR_EX                                              !3
         11        DO_FCALL                                      0  $8      
         12        SEND_VAR                                                 $8
         13        DO_FCALL                                      0          
         14      > JMP                                                      ->35
   20    15    >   INIT_FCALL                                               'is_numeric'
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $10     
         18      > JMPZ                                                     $10, ->31
   21    19    >   INIT_METHOD_CALL                                         !1, 'addChild'
         20        INIT_FCALL                                               'preg_replace'
         21        SEND_VAL                                                 '%2Fs%24%2F'
         22        SEND_VAL                                                 ''
         23        INIT_METHOD_CALL                                         !1, 'getName'
         24        DO_FCALL                                      0  $11     
         25        SEND_VAR                                                 $11
         26        DO_ICALL                                         $12     
         27        SEND_VAR_NO_REF_EX                                       $12
         28        SEND_VAR_EX                                              !2
         29        DO_FCALL                                      0          
         30      > JMP                                                      ->35
   23    31    >   INIT_METHOD_CALL                                         !1, 'addChild'
         32        SEND_VAR_EX                                              !3
         33        SEND_VAR_EX                                              !2
         34        DO_FCALL                                      0          
   16    35    > > JMP                                                      ->3
         36    >   FE_FREE                                                  $4
   27    37      > RETURN                                                   null

End of function arraytoxml

End of class convert.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
132.6 ms | 1409 KiB | 19 Q