这是我的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;
}
我做错了吗?
答案 0 :(得分:1)
我能够解决这个问题。这是修改后的代码:
foreach($xml2->users[0] as $user) {
$userName = $user['name'];
}
感谢ymas,他正确地指出了。