我想从多维数组中获取数组元素ad_id的值。当我使用print_r($ xmls)打印这个数组时,我得到了这个数组:
.....
[5] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ad_id] => 139293
)
[price] => 400,000
[price_comment] => SimpleXMLElement Object
(
)
[location] => Northern NSW
[new_used] => Used
[descript] => Ex fishing fleet mother ship, fully equipped for long range work.
Ideal live aboard cruising /
[Resources] => SimpleXMLElement Object
(
[image] => //imgs.yachthub.com/1/3/9/2/9/3/0_2.jpg
)
)
[6] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ad_id] => 130247
)
[price] => POA
[price_comment] => SimpleXMLElement Object
(
)
[location] => Athens, Greece
[new_used] => Used
[descript] => Luxury motor yacht O’RAMA is 53,54m (175' 7") in length and was built by Golden Yachts in 2009
[Resources] => SimpleXMLElement Object
(
[image] => //imgs.yachthub.com/1/3/0/2/4/7/0_2.jpg
)
)
.....
(这是一个更大的数组,我在这里只写了两个元素。) 我想获得ad_id。我可以使用$ xmls-> Resources-> image获得图像的价值;但是在ad_id的情况下,它不起作用。也许是因为@attributes中的特殊字符?
答案 0 :(得分:0)
$var = "@attributes";
$xmls->$var['ad_id'];
这应该有效