3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $xml = ' <users> <learner name="John"> <rater name="John" email="john@domain.com" group="Self"></rater> <rater name="Jane" email="jane@domain.com" group="Manager"></rater> <rater name="Nathan" email="nathan@domain.com" group="Peers"></rater> </learner> <learner name="Jane"> <rater name="Jane" email="jane@domain.com" group="Self"></rater> <rater name="John" email="john@domain.com" group="Peers"></rater> <rater name="Nathan" email="nathan@domain.com" group="Others"></rater> </learner> </users> '; $sxe = simplexml_load_string($xml); foreach($sxe as $learner){ $name = $learner->attributes()['name']; echo "Learner $name <br/>\n"; foreach($learner->rater as $rater){ foreach($rater->attributes() as $key => $value){ echo " - $key = $value <br/>\n"; } } }
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Learner John <br/> - name = John <br/> - email = john@domain.com <br/> - group = Self <br/> - name = Jane <br/> - email = jane@domain.com <br/> - group = Manager <br/> - name = Nathan <br/> - email = nathan@domain.com <br/> - group = Peers <br/> Learner Jane <br/> - name = Jane <br/> - email = jane@domain.com <br/> - group = Self <br/> - name = John <br/> - email = john@domain.com <br/> - group = Peers <br/> - name = Nathan <br/> - email = nathan@domain.com <br/> - group = Others <br/>
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/hDJet on line 20
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/hDJet on line 20
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/hDJet on line 20
Process exited with code 255.