3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<?xml version="1.0" encoding="UTF-8"?> <translations> <translation id="title"> <english name="name1" ad="ad1">Hello there, how are you?</english> <italian name="name2" ad="ad2">Ciao, come stai?</italian> </translation> <translation id="text2"> <english name="name3" ad="ad4">222Hello there, how are you?</english> <italian name="name3" ad="ad4">222Ciao, come stai?</italian> </translation> <translation id="text3"> <english name="name5" ad="ad5">333Hello there, how are you?</english> <italian name="name6" ad="ad6">333Ciao, come stai?</italian> </translation> </translations>'; $xml = new SimpleXMLElement($xml); $xml = $xml->translation; //echo $xml->translation->english['ad'].PHP_EOL; //echo $xml->translation['id']->italian['name']; function translate($xml, $id, $lang) { foreach ($xml as $element) { if($element['id'] == $id) { return $element->children('italian'); //foreach($element as $key => $val) { // echo $element['id']."{$key}: {$val}".PHP_EOL; //} } } } var_dump(translate($xml, 'text2', 'italian'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HaAW0
function name:  (null)
number of ops:  16
compiled vars:  !0 = $xml
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0A%3Ctranslations%3E%0A++++%3Ctranslation+id%3D%22title%22%3E%0A++++++++%3Cenglish+name%3D%22name1%22+ad%3D%22ad1%22%3EHello+there%2C+how+are+you%3F%3C%2Fenglish%3E%0A++++++++%3Citalian+name%3D%22name2%22+ad%3D%22ad2%22%3ECiao%2C+come+stai%3F%3C%2Fitalian%3E%0A++++%3C%2Ftranslation%3E%0A++++%3Ctranslation+id%3D%22text2%22%3E%0A++++++++%3Cenglish+name%3D%22name3%22+ad%3D%22ad4%22%3E222Hello+there%2C+how+are+you%3F%3C%2Fenglish%3E%0A++++++++%3Citalian+name%3D%22name3%22+ad%3D%22ad4%22%3E222Ciao%2C+come+stai%3F%3C%2Fitalian%3E%0A++++%3C%2Ftranslation%3E%0A++++%3Ctranslation+id%3D%22text3%22%3E%0A++++++++%3Cenglish+name%3D%22name5%22+ad%3D%22ad5%22%3E333Hello+there%2C+how+are+you%3F%3C%2Fenglish%3E%0A++++++++%3Citalian+name%3D%22name6%22+ad%3D%22ad6%22%3E333Ciao%2C+come+stai%3F%3C%2Fitalian%3E%0A++++%3C%2Ftranslation%3E%0A%3C%2Ftranslations%3E'
   20     1        NEW                                              $2      'SimpleXMLElement'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $2
   21     5        FETCH_OBJ_R                                      ~5      !0, 'translation'
          6        ASSIGN                                                   !0, ~5
   40     7        INIT_FCALL                                               'var_dump'
          8        INIT_FCALL                                               'translate'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 'text2'
         11        SEND_VAL                                                 'italian'
         12        DO_FCALL                                      0  $7      
         13        SEND_VAR                                                 $7
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Function translate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/HaAW0
function name:  translate
number of ops:  16
compiled vars:  !0 = $xml, !1 = $id, !2 = $lang, !3 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   27     3      > FE_RESET_R                                       $4      !0, ->14
          4    > > FE_FETCH_R                                               $4, !3, ->14
   28     5    >   FETCH_DIM_R                                      ~5      !3, 'id'
          6        IS_EQUAL                                                 !1, ~5
          7      > JMPZ                                                     ~6, ->13
   29     8    >   INIT_METHOD_CALL                                         !3, 'children'
          9        SEND_VAL_EX                                              'italian'
         10        DO_FCALL                                      0  $7      
         11        FE_FREE                                                  $4
         12      > RETURN                                                   $7
   27    13    > > JMP                                                      ->4
         14    >   FE_FREE                                                  $4
   36    15      > RETURN                                                   null

End of function translate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.47 ms | 1394 KiB | 16 Q