How to access object properties with names like integers?

后端 未结 7 962
故里飘歌
故里飘歌 2020-11-21 22:14

I am using json_decode() something like:

$myVar = json_decode($data)

Which gives me output like this:

[highlig         


        
7条回答
  •  忘掉有多难
    2020-11-21 22:53

    If an object begins with @ like:

    SimpleXMLElement Object (
        [@attributes] => Array (
            [href] => qwertyuiop.html
            [id] => html21
            [media-type] => application/xhtml+xml
        )
    )
    

    You have to use:

    print_r($parent_object->attributes());
    

    because $parent_object->{'@attributes'} or $parent_object['@attributes'] won't work.

提交回复
热议问题