[Villa] => Array
(
[0] => SimpleXMLElement Object
(
[VillaID] => 6
[VillaName] => Mary
[Distances] => SimpleXMLElement Object
(
[Distance] => Array
(
[0] => SimpleXMLElement Object
(
[Destination] => Sea
[Value] => 1000 m
)
[1] => SimpleXMLElement Object
(
[Destination] => Market
[Value] => 800 m
)
)
)
)
[1] => SimpleXMLElement Object
(
[VillaID] => 21
[VillaName] => Marion
[Distances] => SimpleXMLElement Object
(
[Distance] => Array
(
[0] => SimpleXMLElement Object
(
[Destination] => Beach
[Value] => 5 min
)
)
)
)
)
我只需要1个别墅(例如使用id = 6),但打印所有,VillaId不是数组所以不可能用foreach得到所有的SimpleXML如何访问同一节点的所有元素
我可以通过以下方式获得: echo'别墅名称:'。$ xml->别墅[0] - >别墅名称'。
'; 等等......但这样不得不为每个别墅(太多)手动更改括号中的值。 我试过用$ xml-> Villa [$ value] - > VillaName; ($价值来自另一页),但它不工作... 坦克求救!