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?
✗ Incorrect
json_encode() converts PHP data into a JSON string.
What does json_decode() return by default?
✗ Incorrect
By default, json_decode() returns a PHP object unless the second parameter is set to true.
How do you get an associative array from json_decode()?
✗ Incorrect
Passing true as the second parameter to json_decode() returns an associative array.
What type of data can json_encode() convert?
✗ Incorrect
json_encode() can convert PHP arrays and objects into JSON strings.
What happens if json_decode() receives invalid JSON?
✗ Incorrect
json_decode() returns null if the JSON string is invalid.
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.