3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{"key1":"value1","key2":"value2"}'; $asObject = json_decode($json); var_dump($asObject); $asArray = json_decode($json, true); var_dump($asArray); foreach($asArray as $v){ echo $v; } // no problem; $asArray['anotherKey'] = 'anotherValue'; // no problem foreach($asObject as $v){ echo $v; } $asObject['anotherKey'] = 'anotherValue'; // E_ERROR : type 1 -- Cannot use object of type stdClass as array

preferences:
46.47 ms | 2065 KiB | 5 Q