Cannot access data in a xml string
- by Jess McKenzie
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) {
}
}