Home>Article>Backend Development> How to convert json to array in php?
In PHP, you can use the json_decode() function to convert json format data into an array. The json_decode() function can convert a json string into an object or array. It is converted into an object by default. Specify the second parameter as a Boolean value true, so that the JSON value will be decoded into an associative array.
json_decode() function is a built-in function in PHP, used to decode JSON format strings and convert JSON format strings into PHP Variable (object or array). [Related tutorial recommendations: "PHP Tutorial"]
By default, the json_decode() function will return an object; however, you can specify the second parameter to be a Boolean value true, so JSON values will be decoded into associative arrays.
Basic syntax:
json_decode( $json, $assoc = FALSE, $depth = 512, $options = 0 )
Parameters:
Return value:This function returns the encoded JSON value in the appropriate PHP type. If the json cannot be decoded or the encoded data is deeper than the recursion limit, NULL is returned.
Example:
object(stdClass)[1] public 'a' => int 1 public 'b' => int 2 public 'c' => int 3 public 'd' => int 4 public 'e' => int 5 array (size=5) 'a' => int 1 'b' => int 2 'c' => int 3 'd' => int 4 'e' => int 5
Recommended learning:
The above is the detailed content of How to convert json to array in php?. For more information, please follow other related articles on the PHP Chinese website!