I’ve been pulling my hair out over this, I really hope I can get some help. Thanks in advance!
I have a SimpleXML object, which goes something like this:
Object
(
| SomeStuff Object
| (
| )
| Entries Object
| (
| | Entry Object
| | (
| | | SomeMoreStuff Object
| | | (
| | | )
| | | ImportantStuff Object
| | | (
| | | | W1 Object
| | | | (
| | | | | D1 Object
| | | | | (
| | | | | )
| | | | | D2 Object
| | | | W2 Object
| | | | (
| | | | | D1 Object
| | | | | (
| | | | | )
| | | | | D2 Object
…, etc.
For some reason, using the following code produces unexpected results:
foreach($xml->Entries->Entry->ImportantStuff as $key => $value) {
echo "$key, $value";
}
Just outputs ImportantStuff, instead of a line for each D#. In another situation, I have an object where each member of ImportantStuff has the same name, and in this case I use $xml->ImportantStuff->ImportantThing, which returns all ImportantThings. How can I emulate this where the important things have different names?
using simplexml you need to do the foreach like this
foreach($xml->Entries->Entry->ImportantStuff->children() as $key => $value) {
echo "$key, $value";
}