3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json_1 = '[{"MobileNo":"123"},{"MobileNo":"456"}]'; $json_2 = '[{"MobileNo":"07123456701"}]'; $multiple = json_decode($json_1, true); $single = json_decode($json_2, true); 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 as $mobile) { $i++; $array[$i]['SubmitResult'] = [ 'MobileNo' => $mobile['MobileNo'], '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 = 19, Position 2 = 29
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 29
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/o2fbn
function name:  (null)
number of ops:  43
compiled vars:  !0 = $json_1, !1 = $json_2, !2 = $multiple, !3 = $single, !4 = $xml, !5 = $array, !6 = $i, !7 = $mobile, !8 = $convert
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%5B%7B%22MobileNo%22%3A%22123%22%7D%2C%7B%22MobileNo%22%3A%22456%22%7D%5D'
    3     1        ASSIGN                                                   !1, '%5B%7B%22MobileNo%22%3A%2207123456701%22%7D%5D'
    5     2        INIT_FCALL                                               'json_decode'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $11     
          6        ASSIGN                                                   !2, $11
    6     7        INIT_FCALL                                               'json_decode'
          8        SEND_VAR                                                 !1
          9        SEND_VAL                                                 <true>
         10        DO_ICALL                                         $13     
         11        ASSIGN                                                   !3, $13
   24    12        NEW                                              $15     'SimpleXMLElement'
         13        SEND_VAL_EX                                              '%3CMsg+%2F%3E'
         14        DO_FCALL                                      0          
         15        ASSIGN                                                   !4, $15
   25    16        ASSIGN                                                   !5, <array>
   27    17        ASSIGN                                                   !6, 0
   28    18      > FE_RESET_R                                       $20     !2, ->29
         19    > > FE_FETCH_R                                               $20, !7, ->29
   29    20    >   PRE_INC                                                  !6
   31    21        FETCH_DIM_R                                      ~24     !7, 'MobileNo'
         22        INIT_ARRAY                                       ~25     ~24, 'MobileNo'
   32    23        ADD_ARRAY_ELEMENT                                ~25     0, 'StatusId'
   33    24        ADD_ARRAY_ELEMENT                                ~25     'Success%3A+Message+submitted+successfully', 'StatusText'
   30    25        FETCH_DIM_W                                      $22     !5, !6
         26        ASSIGN_DIM                                               $22, 'SubmitResult'
   33    27        OP_DATA                                                  ~25
   28    28      > JMP                                                      ->19
         29    >   FE_FREE                                                  $20
   39    30        NEW                                              $26     'convert'
         31        DO_FCALL                                      0          
         32        ASSIGN                                                   !8, $26
   40    33        INIT_METHOD_CALL                                         !8, 'arrayToXml'
         34        SEND_VAR_EX                                              !5
         35        SEND_VAR_EX                                              !4
         36        DO_FCALL                                      0          
   42    37        INIT_FCALL                                               'var_dump'
         38        INIT_METHOD_CALL                                         !4, 'asXML'
         39        DO_FCALL                                      0  $30     
         40        SEND_VAR                                                 $30
         41        DO_ICALL                                                 
         42      > 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/o2fbn
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
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2      > FE_RESET_R                                       $4      !0, ->36
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->36
          4    >   ASSIGN                                                   !3, ~5
   10     5        TYPE_CHECK                                  128          !2
          6      > JMPZ                                                     ~7, ->15
   11     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
   13    15    >   INIT_FCALL                                               'is_numeric'
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $10     
         18      > JMPZ                                                     $10, ->31
   14    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
   16    31    >   INIT_METHOD_CALL                                         !1, 'addChild'
         32        SEND_VAR_EX                                              !3
         33        SEND_VAR_EX                                              !2
         34        DO_FCALL                                      0          
    9    35    > > JMP                                                      ->3
         36    >   FE_FREE                                                  $4
   20    37      > RETURN                                                   null

End of function arraytoxml

End of class convert.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.55 ms | 1404 KiB | 21 Q