Home >Backend Development >PHP Problem >How to convert JSON string to array in PHP

How to convert JSON string to array in PHP

Guanhui
GuanhuiOriginal
2020-05-12 16:34:105432browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn