What is the purpose of using json_decode() with the second parameter set to true in PHP?
When using json_decode() in PHP, setting the second parameter to true will return the decoded JSON data as an associative array instead of an object. This can be useful when you want to work with the data in array format for easier manipulation or access.
// JSON data to be decoded
$jsonData = '{"name": "John", "age": 30, "city": "New York"}';
// Decoding JSON data into an associative array
$decodedData = json_decode($jsonData, true);
// Accessing the decoded data as an associative array
echo $decodedData['name']; // Output: John
echo $decodedData['age']; // Output: 30
echo $decodedData['city']; // Output: New York