Is there any more elegant way to escape SimpleXML attributes to an array?
$result = $xml->xpath( $xpath );
$element = $result[ 0 ];
$attributes = (array)
Don't directly read the '@attributes' property, that's for internal use. Anyway, attributes() can already be used as an array without needing to "convert" to a real array.
For example:
';
$x = new SimpleXMLElement($xml);
$attr = $x->test[0]->a[0]->attributes();
echo $attr['a']; // "b"
If you want it to be a "true" array, you're gonna have to loop:
$attrArray = array();
$attr = $x->test[0]->a[0]->attributes();
foreach($attr as $key=>$val){
$attrArray[(string)$key] = (string)$val;
}