How to access element attributes using SimpleXml?

How can I access attribute values ​​in php:

[photos] => SimpleXMLElement Object
    (
        [@attributes] => Array
            (
                [page] => 1
                [pages] => 1
                [perpage] => 24
                [total] => 18
            )

I tried the following:

$photos->@attributes['total'] ;
$photos->{'@attributes'}['total'] ;

and many variations of this

+3
source share
1 answer

Simply

echo $photos['total'];

See Example # 5 Using Attributes

+8
source

Source: https://habr.com/ru/post/1784061/


All Articles