From a JSON array I want to create a PHP code and write it to MySQL. How can I do this? Below is my JSON array:
{ "school1":[ { "name":"aaa Universe", "url":"http:\/\/aaa_Universe.com\/" }, { "name":"bbb Universe", "url":"http:\/\/bbb_Universe.com\/" } ], .................................... .................................... "school4":[ { "name":"ggg Universe", "url":"http:\/\/ggg_Universe.com\/" }, { "name":"hhh Universe", "url":"http:\/\/hhh_Universe.com\/" } ] } I have written below PHP script to get expected result. Could you suggest other way:
$data = file_get_contents ("list.json"); $json = json_decode($data, true); foreach ($json as $key => $value) { if (!is_array($value)) { echo $key . '=>' . $value . '<br/>'; } else { foreach ($value as $key => $val) { echo $key . '=>' . $val . '<br/>'; } } }
json_decode($data, true);won't work?