Fatal error: Cannot use object of type stdClass as array (php json_decode)
by z3n on Feb.17, 2010, under Coding, Notes, Tips & Hints
Problem:
$var=json_decode($_POST['something']);
echo $var['value'];
returns error: Fatal error: Cannot use object of type stdClass as array
Solution:
echo $var->value;
2 comments for this entry:
April 9th, 2010 on 8:43
Alternatively, you can pass “true” as a second parameter to json_encode, and it’ll be an associative array.
$var=json_decode($_POST['something'],true);
echo $var['value'];
January 31st, 2011 on 6:15
thanks mate , you are awesome ,