【发布时间】:2017-03-30 10:15:21
【问题描述】:
我有以下 SimpleXMLElement:
object(SimpleXMLElement)#10 (3) {
["@attributes"]=> array(3) {
["id"]=> string(8) "18022352"
["name"]=> string(14) "The Salmon Man"
["slug"]=> string(14) "the-salmon-man"
}
["bids"]=> object(SimpleXMLElement)#11 (1) {
["price"]=> array(1) {
[0]=> object(SimpleXMLElement)#13 (1) {
["@attributes"]=> array(4) {
["decimal"]=> string(4) "9.60"
["percent"]=> string(5) "10.42"
["backers_stake"]=> string(5) "40.36"
["liability"]=> string(6) "347.00"
}
}
}
}
["offers"]=> object(SimpleXMLElement)#12 (1) {
["price"]=> array(1) {
[0]=> object(SimpleXMLElement)#15 (1) {
["@attributes"]=> array(4) {
["decimal"]=> string(4) "9.20"
["percent"]=> string(5) "10.87"
["backers_stake"]=> string(5) "85.35"
["liability"]=> string(5) "10.41"
}
}
}
}
}
为什么会这样:
$horse[0]['name']
但这不是:
$horse[0]['bids'] // also tried $horse['bids'] and other ways
我可以得到如下值,但我希望搜索较小的对象:
$xml->xpath("//odds/event[@id='$matchid']/market[@slug='to-win']/contract[@name='$pony']/bids"); // $pony == $horse[0]['name']
【问题讨论】:
标签: php xml-parsing simplexml