0

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?

1 Answer 1

1

It won't save because $phone is a scalar copy of the original value.

You should be able to reach your goal like this:

foreach($gdNodes->phoneNumber as $key => $phone) { $gdNodes->phoneNumber[$key] = '1234567'; } 
Sign up to request clarification or add additional context in comments.

1 Comment

$key outputs 'phoneNumber'. Looks like I'll have to do it with a for loop. Thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.