So I'm not sure whether to call it "multidimensional" or "nested" or what, but basically I've written an API (just some PHP that creates a well formed XML document of products and their related information via some looped MySQL queries) assuming there is a correct "apikey" on the end of the url.
Now that I have this, I'm trying to loop back through the xml and get the data printed back on the screen nicely...but I'm hitting a wall with the php5 simpleXML (which doesn't seem to be that simple at all...)
Here's the code I'm using to read the XML into an array...
$xml=simplexml_load_string(file_get_contents('http://www.example.com/api.php?apikey=1234567'));
echo"<pre>";
var_dump($xml);
echo"</pre>";
Now, I can see everything fine with var_dump($xml);, but I can't seem to get at anything deeper than the first level with a foreach loop.
Shouldn't I be able to access the elements with something like...
foreach($xml['product_list']['product'] as $k=>$v){echo"K:$k<br>V:$v<br><br>";}
When I try that, I get Warning: Invalid argument supplied for foreach()
I have attached the XML and what I get when I do the var_dump($xml). They are both kind of long...
I have also tried to copy paste some of the examples from some tutorials, but they only show getting the first level elements anyway and I can seem to make them recursive.
Where did I go wrong and what part of my php do I need a remedial crash course in?