I have an xml formatted like this:
<?xml version="1.0"?>
<root>
<foo id="1">
<bar>text</bar>
</foo>
<foo id="2">
<bar>text2</bar>
</foo>
</root>
I know that, in PHP, you I can access the nth element of an xml file loaded with SimpleXML like so:
$xml = simplexml_load_file('file.xml');
echo $xml->foo[2]->bar;
but I need to access an element by a variable pulled from $_GET
, so:
echo $xml->foo[$var]->bar;
This doesn't seem to work, and I'd really appreciate any advice. Thanks!