【发布时间】:2019-02-06 04:58:10
【问题描述】:
如何将此数组输出到 html 表中? 对于每一行,我想在 foreach 中像这样输出它;
echo "<td>".$lat."</td><td>".$long."</td>";
根据https://developer.here.com/documentation/routing-waypoints/topics/quick-start-simple-car.html 上的示例
我已经尝试过代码
$api_url = "https://wse.api.here.com/2/findsequence.json?start=Berlin-Main-Station;52.52282,13.37011&destination1=East-Side-Gallery;52.50341,13.44429&destination2=Olympiastadion;52.51293,13.24021&end=HERE-Berlin-Campus;52.53066,13.38511&mode=fastest;car&app_id=ID&app_code=CODE";
$api_response = file_get_contents($api_url);
$api_response_decoded = json_decode($api_response, true);
foreach($api_response_decoded as $api_response_decoded_row){
print_r($api_response_decoded_row[0][waypoints]);
}
也试过了
print_r($api_response_decoded_row[0][waypoints][id]);
也试过了
echo($api_response_decoded_row[0][waypoints][id]);
也试过了
implode($api_response_decoded_row[0][waypoints][id]);
【问题讨论】:
-
请帮我改进这个问题 - 为什么要投反对票?我用谷歌搜索了它,花了大约 2 个小时从 stackoverflow 和其他网站尝试各种事情 - 我当然尝试自己先解决它!
-
你在哪里尝试在 html 表中输出数组?你有一个json,但你只使用
print_r、echo和implode,html结构在哪里?你能告诉我们你从这 3 种方式中得到了什么以及你想要什么吗? -
对于每一行
echo "<td>".$lat."</td><td>".$long."</td>";见编辑,这说明清楚了吗? -
你试过
$api_response_decoded_row['results']['waypoints']吗? -
另外,感谢投反对票的人删除:-)。
标签: php html arrays json multidimensional-array