php - multidimensional array json_decode (first level) -
i have json file this:
{ "numeric1": { "id": "numeric1", "name": "alphanumeric1", "key": "alphanumeric2", "expire": "alphanumeric3", "status": true, "ads": true }, etc... } with (etc...) mean matrix repeated more times. parse php using:
$allowed = json_decode(file_get_contents("allowed.json"), true); then array like:
array ( [0] => array ( [id] => numeric1 [name] => alphanumeric1 [key] => alphanumeric2 [expire] => alphanumeric3 [status] => 1 [ads] => 1 ) etc.... ) so lose first level of associative keys, have
[0] => arrayinstead of
["numeric1"] => array
how can keep first level of json array? thanks.
try this:
$allowed = (array) json_decode(file_get_contents("allowed.json")); so instead of directly parsing json array (by specifying second parameter of json_decode), first object preserve key, cast array.
Comments
Post a Comment