如何访问 PHP SimpleXMLElement 属性?
How to access PHP SimpleXMLElement attributes?
这是我的xml对象。我无法在脚本的对象数组中解析它。
SimpleXMLElement Object(
[pagination] => SimpleXMLElement Object
(
[@attributes] => Array
(
[pageNumber] => 1
[pageSize] => 100
[totalAvailable] => 1
)
)
[users] => SimpleXMLElement Object
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => xxxxxxxx
[name] => xxxxx
[siteRole] => xxxxx
[lastLogin] => xxxxxx
[externalAuthUserId] =>
)
)
)
)
这是我的 PHP 代码:
foreach($xml2->users as $item) {
$userName = $item->attributes()->name;
}
我是不是做错了什么?
我能够解决问题。这是修改后的代码:
foreach($xml2->users[0] as $user) {
$userName = $user['name'];
}
感谢 ymas 他指出正确。
这是我的xml对象。我无法在脚本的对象数组中解析它。
SimpleXMLElement Object(
[pagination] => SimpleXMLElement Object
(
[@attributes] => Array
(
[pageNumber] => 1
[pageSize] => 100
[totalAvailable] => 1
)
)
[users] => SimpleXMLElement Object
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => xxxxxxxx
[name] => xxxxx
[siteRole] => xxxxx
[lastLogin] => xxxxxx
[externalAuthUserId] =>
)
)
)
)
这是我的 PHP 代码:
foreach($xml2->users as $item) {
$userName = $item->attributes()->name;
}
我是不是做错了什么?
我能够解决问题。这是修改后的代码:
foreach($xml2->users[0] as $user) {
$userName = $user['name'];
}
感谢 ymas 他指出正确。