json_encode/json_decode - returns stdClass instead of Array in PHP

前端 未结 7 2217
太阳男子
太阳男子 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:38

    Although, as mentioned, you could add a second parameter here to indicate you want an array returned:

    $array = json_decode($json, true);
    

    Many people might prefer to cast the results instead:

    $array = (array)json_decode($json);
    

    It might be more clear to read.

提交回复
热议问题