problem with SimpleXML and inclosed arrays
I'm having a problem with SIMPLE XML. I seem to have an array with dumping the whole object. However, when I try to access the array, I get a single element of the array back.
Here is the full dump:
SimpleXMLElement Object
(
[@attributes] => Array
(
[type] => array
)
[person] => Array
(
[0] => SimpleX开发者_高级运维MLElement Object
(
..........................
),
[1] => SimpleXMLElement Object
(
..........................
)
)
)
when I try to access the person array through $xml->person, instead of getting the array, I get the first element back. Any ideas?
From the SimpleXML Basic usage documentation in the PHP Manual:
NOTE: Properties (
$xml->movie
in previous example) are not arrays. They are iterable and accessible objects.
So, in your case, $xml->person
is not actually an array, just an iterable object. It can be easily converted to an array with:
$persons = array();
foreach ($xml->person as $person) {
$persons[] = $person;
}
精彩评论