Last active
February 20, 2016 11:33
-
-
Save useless-stuff/8bb90338de9b985a9209 to your computer and use it in GitHub Desktop.
PHP - SimpleXMLIterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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