Skip to content
Advertisement

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

i have a json file which i have decoded.Now i am trying to print the each element in the array which are “id,bin,tur,bank_name” etc. How can i reach the for example second element of the array and print it as a table.

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

and my output is looking like this;

Array

(

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

Advertisement

Answer

you can simply iterate on the array and display them:

$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>";

change in the $record keys to add or remove elements you need to display.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement