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

How to convert JSON string to array in PHP

Guanhui
Release: 2023-03-01 07:34:01
Original
5435 people have browsed it

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));
Copy after login

Print result:

array(5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
    ["e"] => int(5)
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template