Hey folks,
I’m at my limits on SimpleXML knowledge. Suppose I have two SimpleXMLElements:
$sessions and $events
$sessions members basically contain FK’s to their parent $event PK’s. And I’d like to put add a reference in the each $event member’s sessions. My initial thought was something like this:
[code=php]foreach ($sessions as $s) {
foreach ($events as $e) {
if ((string)$s->parent_id == (string)$e->id) {
$e->addChild(‘session’, $s);
}
}
}
The code above ultimately adds “blank” children though — presumably adding a reference to the loop-local $s. And while it seems odd that $s would go out of scope and not $e, the logical solution (in my mind) would be the change the loops:
[code=php]foreach ($sessions as &$s) {
foreach ($events as &$e) {
if ((string)$s->parent_id == (string)$e->id) {
$e->addChild(‘session’, $s);
}
}
}
No dice again — not allowed: [I]Fatal error: An iterator cannot be used with foreach by reference in …
Thoughts?
Thanks,