Accessing @attribute from SimpleXML

前端 未结 8 1390
后悔当初
后悔当初 2020-11-22 00:33

I am having a problem accessing the @attribute section of my SimpleXML object. When I var_dump the entire object, I get the correct output, and wh

8条回答
  •  一个人的身影
    2020-11-22 01:11

    I used before so many times for getting @attributes like below and it was a little bit longer.

    $att = $xml->attributes();
    echo $att['field'];
    

    It should be more easy and you can get attributes following format only at once:

    Standard Way - Array-Access Attributes (AAA)

    $xml['field'];
    

    Other alternatives are:

    Right & Quick Format

    $xml->attributes()->{'field'};
    

    Wrong Formats

    $xml->attributes()->field;
    $xml->{"@attributes"}->field;
    $xml->attributes('field');
    $xml->attributes()['field'];
    $xml->attributes->['field'];
    

提交回复
热议问题