When I encode an array with json_encode()
in PHP
, all gets done right till here, but when I decode it back with json_decode()
, it gives me stdClass
Object instead of an Array.
Here is my code:
echo $json=json_encode(array('a'=>1,'b'=>2));
echo '<br>';
print_r(json_decode($json));
// and the result of PHP script is :
{"a":1,"b":2}
// stdClass Object ( [a] => 1 [b] => 2 )
what converts it into object from an array ??
can i pass the json encoded string into url to get data on another page, or there exists any function that can do some url encoding ?
json_decode() needs an extra parameter to decode to an array.
json_decode($json, 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