【问题标题】:How can i print the data in the array of json file in php如何在php中打印json文件数组中的数据
【发布时间】:2022-01-10 03:32:26
【问题描述】:

我有一个我已经解码的 json 文件。现在我正在尝试打印数组中的每个元素,它们是“id、bin、tur、bank_name”等。我怎样才能到达例如数组的第二个元素并将其打印为表格。

$json_url = "websitename";
        $json = file_get_contents($json_url);
        $data = json_decode($json, TRUE);
        echo "<pre>";
        print_r($data);
        echo "</pre>";
      

我的输出是这样的;

数组

(

[0] => Array
    (
        [id] => 13355
        [bin] => 540134
        [tur] => mc
        [banka_adi] => T.C.ZİRAAT BANKASI A.Ş.
        [type] => maximum
        [name] => ziraat
        [created_at] => 2019-08-11 21:10:12
        [updated_at] => 2019-08-11 21:10:12
        [ekalan] => 
    )

[1] => Array
    (
        [id] => 13356
        [bin] => 547287
        [tur] => mc
        [banka_adi] => T.C.ZİRAAT BANKASI A.Ş.
        [type] => maximum
        [name] => ziraat
        [created_at] => 2019-08-11 21:10:12
        [updated_at] => 2019-08-11 21:10:12
        [ekalan] => 
    )

[2] => Array
    (
        [id] => 13357
        [bin] => 542374
        [tur] => mc
        [banka_adi] => T.C.ZİRAAT BANKASI A.Ş.
        [type] => maximum
        [name] => ziraat
        [created_at] => 2019-08-11 21:10:12
        [updated_at] => 2019-08-11 21:10:12
        [ekalan] => 
    )

【问题讨论】:

    标签: php html json


    【解决方案1】:

    您可以简单地迭代数组并显示它们:

    $json_url = "websitename";
    $json = file_get_contents($json_url);
    $data = json_decode($json, true);
    echo "<table>";
    foreach($data as $record) {
       echo "<tr>";
       echo "<td>" . $record["id"] . "/<td>";
       echo "<td>" . $record["bin"] . "/<td>";
       echo "<td>" . $record["tur"] . "/<td>";
       echo "</tr>";
    }
    echo "</table>";
    
    

    更改$record 键以添加或删除您需要显示的元素。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      • 2017-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-24
      • 1970-01-01
      相关资源
      最近更新 更多