【发布时间】:2017-09-25 16:14:26
【问题描述】:
在遍历下面的 xml 对象时,我需要从每个属性中获取数据,如果属性不存在,则继续。我不确定如何检查@attributes 是否存在。目前,如果它没有我的循环死亡。
我试过了:
if(isset($v[0]->user->attributes())){
....
but that gives me a php error:
Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
所以我不确定如何检查它是否存在,如果存在我可以通过循环运行。如果不行,我可以继续……
[server] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 17980
)
[user] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1075159
[default-loc] => 50000
[status] => 1
[license] => high,standard
[password] => aebecf880f2060c31e44f820785e0aa63ea4cc44
[primary] => 50000
[username] => 17980_50000
)
[description] => Customer X
)
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 14642
)
[user] => Array
(
[0] => SimpleXMLElement Object
(
[description] => Customer Y
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 24151
)
[user] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 1075159
[default-loc] => 50000
[status] => 1
[license] => high,low
[password] => aebecf880f2060c31e44f820785e0aa63ea4cc44
[primary] => 51412
[username] => 17980_51412
)
[description] => Customer Z
)
)
)
)
【问题讨论】:
-
与您的问题无关,但您的密码似乎使用 SHA1 进行了哈希处理。请注意,这对于现代安全目的不够。