3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $xml = new SimpleXMLElement('<items><item action="preview" /></items>'); foreach ($xml->xpath('/items/item') as $item) { var_dump($item); var_dump($item->xpath("(.)[@action='preview']/@action")); }
based on enkJG
Output for 5.6.0 - 5.6.30, hhvm-3.12.14 - 3.17.3, 7.0.0 - 7.1.20
object(SimpleXMLElement)#2 (1) { ["@attributes"]=> array(1) { ["action"]=> string(7) "preview" } } array(1) { [0]=> object(SimpleXMLElement)#3 (1) { ["@attributes"]=> array(1) { ["action"]=> string(7) "preview" } } }