How do I get an array as a result from json_decode()
?
I had an array like this:
$array = array(
'mod_status' => 'yes',
'mod_newsnum' => 5
);
and I saved this in database like JSON encode:
{"mod_status":"yes","mod_newsnum":5}
Now I want to get array again from database. But when i use:
$decode = json_decode($dbresult);
I get:
stdClass Object (
[mod_status] => yes
[mod_newsnum] => 5
)
Instead of an array. How can I get an array instead of an object?
Set the second parameter of json_decode
to true to force associative arrays:
$decode = json_decode($dbresult, true);
As per http://in3.php.net/json_decode:
$decode = json_decode($dbresult, TRUE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With