我需要创建html表...
使用此代码:
$result = curl_exec($ch);
curl_close($ch);
$json = json_decode($result);
foreach ($json->data->reservations as $element) {
print_r($element);
}//
我收到了这些数据:
stdClass Object ( [id] => 11616946 [property] => NNN [propertyName] => nnn [infourl] => https://domain.com [from] => 2016-07-18 [to] => 2016-07-25 ) [pricing] => stdClass Object ( [price] => 1164.24 [clientInfo] => stdClass Object ( [firstName] => PERA [lastName] => PETROVI [email] => nnn@ravel.com ) [status] => 1 [offline] => 0 ) stdClass Object ( [id] => 11589607 [property] ... ... ... ... etc.
如何使用该数据创建html?如何使用foreach并在每一个ID的那一行创建表?
答案 0 :(得分:1)
了解您期望的JSON数据的结构,您可以使用JSON数据动态构建<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text
<br>
<img src=http://cdn-img.health.com/sites/default/files/styles/400x400/public/styles/400x400/public/styles/main/public/how-take-care-cat-400x400.jpg?itok=ta2kPB58>
</p>
循环中的表,如下所示:
foreach
答案 1 :(得分:0)
打开以下链接有完整指南。如何用php创建html表,包括设置属性,数据和打印。
链接: - https://pear.php.net/manual/en/package.html.html-table.intro.php
答案 2 :(得分:0)
您在数组索引中获取了一个对象。如果遍历数组,每个实例都将返回一个对象,您只需要调用其属性,因此您不必再次迭代该值。
尝试:
foreach ($json->data->reservations as $element) {
echo("<table>");
echo("<tr>");
echo("<td>");
echo($element.id);
echo($elenent.propertyName);
//echo($elenent.etc);
echo("</td>");
echo("</tr>");
echo("</table>");
}