php - Edit SimpleXML node in a foreach loop
309
I'm trying to edit a node value while in a loop. I can edit nodes with unique names just fine.
$gdNodes->orgName = 'test';
But when I'm in a loop, the value is not saved when I output my XML.
foreach($gdNodes->phoneNumber as $phone)
{
$phone = '1234567';
}
Both are SimpleXMLElement class objects. I don't understand why it's not saving. How is it done?
Answer
Solution:
It won't save because
$phone
is a scalar copy of the original value.You should be able to reach your goal like this: