Reputation: 285
I load XML
file by simplexml_load_file
XML :
<list>
<top>
<test>
<id>1</id>
</test>
<test>
<id>2</id>
</test>
<test>
<id>3</id>
</test>
</top>
<test>
<id>4</id>
</test>
</list>
I want get all TEST
tag by one foreach
I dont use top
parent for get test
chilren
How i can ?
Upvotes: 0
Views: 49
Reputation: 158
You want all TEST
elements which are anywhere in XML? In that case you can use xpath somelike this
$xml = simplexml_load_file('xml.xml');
$testElements = $xml->xpath('//*/test'); // return array of TEST elements
Upvotes: 1