如何将多个json源文件回显到一个循环中?

时间:2018-08-20 14:05:32

标签: php json

我想从多个json文件中回显数据,但是只有一个json文件可以正常工作。请帮我获取多个json文件。 THX

<?php

$water = file_get_contents('https://example.com/plant.json');
$wall = file_get_contents('https://example.com/door.json'); // How?

$decode = json_decode($water);
$data = $decode->data;

foreach ($data as $datas) {
    echo '<div>' . $datas->ice . '</div>';
    echo '<div>' . $datas->desk . '</div>';
}

/*

Content of plant.json file:
{"data":[
    {"ice":eight,"desk":"six"},
    {"ice":"ten","desk":"cup"}
]}

Content of door.json file:
{"data":[
    {"ice":pen,"desk":"sing"},
    {"ice":"bear","desk":"wire"}
]}

*/

?>

0 个答案:

没有答案