在xml读取中为foreach()提供的参数无效?

时间:2016-12-20 05:41:47

标签: php xml foreach

当我尝试从XML读取时,foreach以为foreach提供的无效参数() XML文件

作为反应

XML File

以下代码用于检索数据

        $availabilityrs = simplexml_load_string($response3);
        $hotel = $availabilityrs->rooms->room;
        $hotel1 = $availabilityrs->rooms->room;
        foreach ($hotel1 as $room) {
           echo "<b>Room Name: </b>".$room['name']."</br>"; 
        }

1 个答案:

答案 0 :(得分:0)

您忘记将hotel添加到您的assign变量。

试试这个;

$availabilityrs = simplexml_load_string($response3);
$hotel = $availabilityrs->hotel->rooms->room; // add hotel
$hotel1 = $availabilityrs->hotel->rooms->room; // add hotel

foreach ($hotel1 as $room) {
    echo "<b>Room Name: </b>".$room['name']."</br>"; 
}