php method to convert a json string into an array: You can use the json_decode function, such as [json_decode($json, true);]. The json_decode function can accept a json format string and convert it into a php variable.
Function introduction:
(Recommended tutorial: php video tutorial)
json_decode accepts one JSON format string and convert it into a PHP variable. When the parameter $assoc is TRUE, array will be returned, otherwise object will be returned.
Grammar format:
json_decode(string $json[,bool $assoc = false[,int $depth = 512[,int $options = 0]]])
Code implementation:
<?php $json = '{"a":"php","b":"mysql","c":3}'; $json_Class=json_decode($json); $json_Array=json_decode($json, true); print_r($json_Class); print_r($json_Array); ?>
Output result:
stdClass Object ( [a] => php [b] => mysql [c] => 3 ) Array ( [a] => php [b] => mysql [c] => 3 )
Related recommendations: php training
The above is the detailed content of How to convert json string to array in php. For more information, please follow other related articles on the PHP Chinese website!