0

I am new to PHP, I have some data from API in json format.

JSON Image

In php i tried

$response = \Httpful\Request::get($uri)->send();

$json = json_decode($response, true);

foreach($json as $k=>$val):
    echo '<b>Name: '.$k.'</b></br>';

endforeach;

echo $response;

echo "<br />";

print_r($json);

echo "<br />";

echo ($json["genres"][0]);

But I am unable to read the array content. Can someone please help me how to parse this PHP array in a loop. Is there any php library to simplify this?

LF00
  • 27,015
  • 29
  • 156
  • 295
raju
  • 6,448
  • 24
  • 80
  • 163

2 Answers2

0

You can try to use the foreach loop in PHP as follows, which worked for me.

    foreach(json_data as $key => $val){
        echo $key . ":" . $val;
    }

I hope it helps.

0

firstly you wrongly used php's foreach, second you have to use $json['genres'] to access the inner array

foreach($json['genres'] as $k=>$val)
{
    echo $k.':'.$val['id'].'_'.$val['name'];
}
LF00
  • 27,015
  • 29
  • 156
  • 295