json_encode/json_decode - returns stdClass instead of Array in PHP

前端 未结 7 2198
太阳男子
太阳男子 2020-12-04 13:54

Observe this little script:

$array = array(\'stuff\' => \'things\');
print_r($array);
//prints - Array ( [stuff] => things )
$arrayEncoded = json_encod         


        
相关标签:
7条回答
  • 2020-12-04 14:43
        var_dump(json_decode('{"0":0}'));    // output: object(0=>0)
        var_dump(json_decode('[0]'));          //output: [0]
    
        var_dump(json_decode('{"0":0}', true));//output: [0]
        var_dump(json_decode('[0]', true));    //output: [0]
    

    If you decode the json into array, information will be lost in this situation.

    0 讨论(0)
提交回复
热议问题