无法访问xml中的属性

时间:2017-05-31 13:00:52

标签: php simplexml

我试图访问简单xml的属性

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [Index] => 21
        )

    [Data] => Hello world
)

我想访问Index属性。我尝试了以下代码,但事实并非如此 为我工作

$xml->attributes()->Index

1 个答案:

答案 0 :(得分:0)

你去找我的朋友:

$xml->attributes()['Index']

有时候我注意到,当它是一个字符串时我必须抛出结果。像:

(string)$xml->attributes()['Index']
相关问题