I have my xml file
<names>
<person>
<name>John</name>
<alias>
<part>Joe</part>
<part>Foo</part>
</alias>
</person>
</names>
which I saved as $xml
.
foreach($xml as $person)
var_dump($person->name);
The above code returns
object(SimpleXMLElement)#7 (1) {
[0]=>
string(4) "John"
}
instead of just
string(4) "John"
With the actual return it gives, I would assume adding [0]
to the end of the variable would give me the correct return, but it returns the exact same thing. I have tried adding [0]
, ["0"]
, ->0
, ->"0"
, and nothing works. The last 2 tries gave me a parse error, while the first 2 gave me the same response as the original.
How can I get the string(4) "John"
from inside the object(SimpleXMLElement)
?