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:
- ##json: It contains the JSON string that needs to be decoded. It only works with UTF-8 encoded strings.
- assoc: This is a Boolean variable. If true, the returned object will be converted to an associative array.
- depth: It represents the user-specified recursion depth.
- options: Bitmask containing JSON_OBJECT_AS_ARRAY, JSON_BIGINT_AS_STRING, JSON_THROW_ON_ERROR.
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:
<?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; var_dump(json_decode($json)); var_dump(json_decode($json, true)); ?>Output:
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version
Chinese version, very easy to use

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
