Sometimes, we want to access @attribute from SimpleXML with PHP.
In this article, we’ll look at how to access @attribute from SimpleXML with PHP.
How to access @attribute from SimpleXML with PHP?
To access @attribute from SimpleXML with PHP, we can use the attributes
method.
For instance, we write
$xml->attributes()->{'field'};
to get the @attributes values with attributes
.
Then we use {'field'}
to get the value of the field with key 'field'
.
Conclusion
To access @attribute from SimpleXML with PHP, we can use the attributes
method.