David David - 1 year ago 120
PHP Question

decode elements of arrays php array from json

trying to get data from json, So far, I can see I have converted the data into a php array which displays it on the page, with the following code:

$jsonurl = 'url';
$json = file_get_contents($jsonurl,0,null,null);
$json_output = var_dump(json_decode($json,true));

This outputs the whole array, the json file stores the name of the business, address, image url, city, etc etc. What I'm confused about is how I just say echo out a list of just say the Name of the business plus the city, as simply printed text, rather then dumping the whole array onto the page.

Answer Source

You can echo the data in a foreach loop:

$json_as_array = json_decode($json,true);
foreach ($json_as_array AS $key => $value) {
    echo $key . ': ' . $value;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download