I am trying to get a consistent array from my XML API result. The problem I am running into is when a parent has one vs multiple children. I get the XML into an array and I expect to loop thru the foreach [posts][post] -> $thispost show all the posts. When I use the first and display $thispost[‘ID’] I get an error because the foreach loop iterates thru the ID and title and not each post. How do I get it to consistently create an array where the [posts][post] is an array of posts?
Example XML vs resulting Arrays.
<posts>
<post>
<ID>1</ID>
<title>First</title>
</post>
</posts>
Resulting [posts] Array
Array
(
[post] => Array
(
[ID] => 1
[title] => First
)
)
VS
<posts>
<post>
<ID>1</ID>
<title>First</title>
</post>
<post>
<ID>2</ID>
<title>Second</title>
</post>
</posts>
Resulting [Posts] Array
Array
(
[post] => Array
(
[0] => Array
(
[ID] => 1
[title] => First
)
[1] => Array
(
[ID] => 2
[title] => Second
)
)
)