Home >Backend Development >PHP Problem >How to convert JSON string to array in PHP
How does PHP convert a JSON string into an array?
In PHP, you can use the "json_decode()" function to convert a JSON string into Array. The function of this function is to decode a string in JSON format. Its syntax is "json_decode(str,assoc)". When using it, just pass the string into the first parameter and set the second parameter to TRUE.
Sample code:
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; var_dump(json_decode($json, true));
Print result:
array(5) { ["a"] => int(1) ["b"] => int(2) ["c"] => int(3) ["d"] => int(4) ["e"] => int(5) }
Recommended tutorial: "PHP Tutorial"
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!