簡體   English   中英

如何在 php 中打印 json 文件數組中的數據

[英]How can i print the data in the array of json file in php

我有一個 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>";
      

我的 output 看起來像這樣;

大批

(

[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] => 
    )

您可以簡單地迭代數組並顯示它們:

$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鍵以添加或刪除您需要顯示的元素。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM