0
0
PHPprogramming~5 mins

JSON encoding and decoding in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does JSON encoding mean in PHP?
JSON encoding means converting PHP data like arrays or objects into a JSON string format that can be easily shared or stored.
Click to reveal answer
beginner
Which PHP function is used to convert a PHP array into a JSON string?
The function json_encode() converts a PHP array or object into a JSON string.
Click to reveal answer
beginner
What does JSON decoding mean in PHP?
JSON decoding means converting a JSON string back into a PHP variable like an array or object.
Click to reveal answer
beginner
Which PHP function is used to convert a JSON string into a PHP variable?
The function json_decode() converts a JSON string into a PHP array or object.
Click to reveal answer
intermediate
What does the second parameter of json_decode() control?
The second parameter controls if the JSON string is decoded into an associative array (true) or an object (false, default).
Click to reveal answer
Which function converts a PHP array to a JSON string?
Ajson_encode()
Bjson_decode()
Cjson_parse()
Djson_to_array()
What does json_decode() return by default?
AA PHP associative array
BA PHP object
CA JSON string
DAn error
How do you get an associative array from json_decode()?
ASet second parameter to true
BSet second parameter to false
CUse json_encode() instead
DUse json_parse()
What type of data can json_encode() convert?
AOnly strings
BOnly numbers
CArrays and objects
DOnly booleans
What happens if json_decode() receives invalid JSON?
AReturns the original string
BThrows an exception
CReturns false
DReturns null
Explain how to convert a PHP array to JSON and back to a PHP array.
Think about the functions and parameters needed for encoding and decoding.
You got /3 concepts.
    Describe the difference between decoding JSON to an object versus an associative array in PHP.
    Focus on the second parameter of json_decode().
    You got /4 concepts.