What is the use of json_decode () in php
This article mainly shows you "what is the use of json_decode () in php". It is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what is the use of json_decode () in php?"
Json_decode ()
This function is used to convert json text into the corresponding PHP data structure. Here is an example:
$json ='{"foo": 12345}'; $obj = json_decode ($json); print $obj- > {'foo'}; / / 12345
Normally, json_decode () always returns a PHP object, not an array. For example:
$json ='{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5}'; var_dump (json_decode ($json))
The result is a PHP object:
Object (stdClass) # 1 (5) {["a"] = > int (1) ["b"] = > int (2) ["c"] = > int (3) ["d"] = > int (4) ["e"] = > int (5)}
If you want to force the generation of PHP associative arrays, json_decode () needs to add a parameter, true:
$json ='{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5}'; var_dump (json_decode ($json,true))
The result is an associative array:
Array (5) {["a"] = > int (1) ["b"] = > int (2) ["c"] = > int (3) ["d"] = > int (4) ["e"] = > int (5)} above are all the contents of the article "what is the use of json_decode () in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!