Cannot access data in a xml string
Posted
by
Jess McKenzie
on Stack Overflow
See other posts from Stack Overflow
or by Jess McKenzie
Published on 2012-11-16T22:53:08Z
Indexed on
2012/11/16
22:59 UTC
Read the original article
Hit count: 227
I am trying to create an array that I can include the perent category Name
and the child category Name
. I can so far access the below object fine using $xml->Subcategories;
but if I try my code below I get an empty array why?
PHP:
foreach ($catDetailsXml->Category as $value)
{
$categoryDetails[] = array('CategoryNumber' => $value->Number);
}
Structure:
object(SimpleXMLElement)#13 (1) {
["Category"]=>
array(5) {
[0]=>
object(SimpleXMLElement)#14 (4) {
["Name"]=>
string(19) "Commercial Property"
["Number"]=>
string(10) "0350-0100-"
["Subcategories"]=>
object(SimpleXMLElement)#35 (1) {
["Category"]=>
array(3) {
[0]=>
object(SimpleXMLElement)#36 (4) {
["Name"]=>
string(9) "Car parks"
["Number"]=>
string(15) "0350-0100-8946-"
["Subcategories"]=>
object(SimpleXMLElement)#39 (0) {
}
}
© Stack Overflow or respective owner