3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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) { $el = $element->children(); var_dump($el->children($lang, true)); //foreach($element as $key => $val) { // echo $element['id']."{$key}: {$val}".PHP_EOL; //} } } } var_dump(translate($xml, 'text2', 'italian'));
based on 2Tltv
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = -2
filename:       /in/SEO1X
function name:  (null)
number of ops:  17
compiled vars:  !0 = $xml
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  16     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      :-5
         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
  25     7        NOP                                                      
  42     8        INIT_FCALL                                               'var_dump'
         9        INIT_FCALL                                               'translate'
        10        SEND_VAR                                                 !0
        11        SEND_VAL                                                 'text2'
        12        SEND_VAL                                                 'italian'
        13        DO_FCALL                                      0  $7      
        14        SEND_VAR                                                 $7
        15        DO_ICALL                                                 
        16      > RETURN                                                   1

Function translate:
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
Jump found. Position 1 = 5, Position 2 = 19
Branch analysis from position: 5
Jump found. Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
Jump found. Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 18
Branch analysis from position: 19
Jump found. Position 1 = -2
Branch analysis from position: 19
filename:       /in/SEO1X
function name:  translate
number of ops:  21
compiled vars:  !0 = $xml, !1 = $id, !2 = $lang, !3 = $element, !4 = $el
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                                       $5      !0, ->19
         4    > > FE_FETCH_R                                               $5, !3, ->19
  28     5    >   FETCH_DIM_R                                      $6      !3, 'id'
         6        IS_EQUAL                                         ~7      $6, !1
         7      > JMPZ                                                     ~7, ->18
  29     8    >   INIT_METHOD_CALL                                         !3, 'children'
         9        DO_FCALL                                      0  $8      
        10        ASSIGN                                                   !4, $8
  31    11        INIT_FCALL                                               'var_dump'
        12        INIT_METHOD_CALL                                         !4, 'children'
        13        SEND_VAR_EX                                              !2
        14        SEND_VAL_EX                                              <true>
        15        DO_FCALL                                      0  $10     
        16        SEND_VAR                                                 $10
        17        DO_ICALL                                                 
        18    > > JMP                                                      ->4
        19    >   FE_FREE                                                  $5
  38    20      > RETURN                                                   null

End of function translate

Generated using Vulcan Logic Dumper, using php 7.2.0