【发布时间】:2020-09-21 13:21:13
【问题描述】:
$curl = curl_init();
$response = curlPost($curl, $url, $headers, http_build_query($body));
$data = json_decode($response, true);
if ($data["success"] === true) {
$hotels = $data["hotels"];
foreach ($hotels as $hotel) {
echo $hotel['name']."<br>";
foreach ($hotel as $key => $value) {
if ($key === "id"){
continue;
}
if ($key === "name"){
continue;
}
echo "{$key}: {$value}" ."<br>";
}
echo PHP_EOL . PHP_EOL."<hr>";
}
} else {
echo $data["reason"];
}
?>
<table>
<thead>
<tr>
<th colspan="2"> NAME OF THE HOTEL </th>
</tr>
</thead>
<tbody>
<tr>
<td>key</td>
<td>value</td>
</tr>
</tbody>
</table>
<hr/>
这是我的代码。如您所见,我正在用 curl 解析一些数据,更具体地说是一些酒店的名称、ID、位置等,并将它们存储在一个名为 data 的变量中。我知道如何打印数据,但我不知道如何将数据放在下表中。例如,我想说<th colspan="2"> HOTEL PARIS HILTON </th> 在<td>location</td> <td>USA</td>etc 下方。
帮助任何人?谢谢
【问题讨论】: