当我尝试从XML读取时,foreach以为foreach提供的无效参数() XML文件
作为反应以下代码用于检索数据
$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>";
}
答案 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>";
}