How to convert json into array in php

藏色散人
Release: 2023-03-02 20:32:01
Original
2993 people have browsed it

php method to convert json into an array: first create a php sample file; then create a set of json format data; then convert json into an array through the "json_decode" function; finally print the conversion result through "var_dump" That’s it.

How to convert json into array in php

php converts json into an array:

As shown below:

//json格式数据
$data = '[{ "F_ModuleId": "1", "F_ParentId": "0", "F_EnCode": "SysManage",}]';
//转换成数组
$arr = json_decode($data,true);
//输出
var_dump($arr);
Copy after login

Recommended: "PHP Tutorial"

Related introduction:

json_decode — Decode a string in JSON format

Description

json_decode ( string $json [, bool $assoc = FALSE [, int $depth = 512 [, int $options = 0 ]]] ) : mixed
Copy after login

Accepts a JSON encoded string and converts it into a PHP variable

Parameters

json

To be decoded A string in json string format.

This function can only handle UTF-8 encoded data.

Note:

PHP implements a superset of JSON as specified in the original » RFC 7159.
Copy after login

assoc

When this parameter is TRUE, array will be returned instead of object.

depth

Specifies the recursion depth.

options

Mask consisting of JSON_BIGINT_AS_STRING, JSON_INVALID_UTF8_IGNORE, JSON_INVALID_UTF8_SUBSTITUTE, JSON_OBJECT_AS_ARRAY, JSON_THROW_ON_ERROR. The behavior of these constants is further described on the JSON constants page.

Return value

Returns data encoded in json via the appropriate PHP type. The values ​​true, false and null return TRUE, FALSE and NULL accordingly. If json cannot be decoded, or the encoded data depth exceeds the recursion limit, NULL will be returned.

The above is the detailed content of How to convert json into 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