Skip to content

Instantly share code, notes, and snippets.

@useless-stuff
Last active February 20, 2016 11:33
Show Gist options
  • Save useless-stuff/8bb90338de9b985a9209 to your computer and use it in GitHub Desktop.
Save useless-stuff/8bb90338de9b985a9209 to your computer and use it in GitHub Desktop.
PHP - SimpleXMLIterator
<?php
$xml = <<<EOF
<results>
<user>
<name>Diego</name>
<surname>Anniballo</surname>
</user>
<user>
<name>Mari</name>
<surname>Monti</surname>
</user>
<user>
<name>Luigi</name>
<surname>Pesto</surname>
</user>
</results>
EOF;
$iterator = new SimpleXMLIterator($xml);
foreach($iterator as $subject){
foreach($subject as $property => $value){
echo $property, ' ', $value, PHP_EOL;
}
}
// Output:
/*
name Diego
surname Anniballo
name Mari
surname Monti
name Luigi
surname Pesto
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment