How can the second parameter of json_decode be utilized to simplify accessing data from JSON objects in PHP?

When working with JSON objects in PHP, accessing nested data can be cumbersome and error-prone. The second parameter of the json_decode function allows you to specify whether you want the data returned as an associative array or an object. By setting this parameter to true, you can simplify accessing data by treating the JSON object as an associative array, making it easier to navigate through the data structure.

$json = '{"name": "John", "age": 30, "city": "New York"}';
$data = json_decode($json, true);

echo $data['name']; // Output: John
echo $data['age']; // Output: 30
echo $data['city']; // Output: New York