[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; ($價值來自另一頁),但它不工作... 坦克求救!