Forum Moderators: coopster
$sxml = new SimpleXMLElement($doc);
foreach ($sxml->children() as $park) {
$key = (string) $park->attributes()->number;
$data[$key]['sheep'] = (string) $park->sheep;
$data[$key]['horse'] = (string) $park->horse;
$data[$key]['dog'] = (string) $park->dog;
$data[$key]['cow'] = (string) $park->cow;
}
print_r($data);
Does your 'park' element still have the 4 children: sheep, horse, dog and cow?
Then if you have 0 attributes...
foreach ($sxml->children() as $park) {
$data[0]['sheep'] = (string) $park->sheep;
$data[0]['horse'] = (string) $park->horse;
$data[0]['dog'] = (string) $park->dog;
$data[0]['cow'] = (string) $park->cow;
} (?) You might as well get rid of the first array dimension [0] as well, but that will depend on the rest of your code. (And you could step through the children() of 'park' rather than specify the elements directly.)