How can the json_decode() function be properly utilized to extract specific data from nested arrays in PHP?

When dealing with nested arrays in JSON data, the json_decode() function in PHP can be used to convert the JSON string into a PHP array. To extract specific data from nested arrays, you can access the elements by chaining array keys or indexes. By traversing through the nested arrays using the appropriate keys or indexes, you can easily extract the desired data.

// Sample JSON data
$json_data = '{"name": "John Doe", "age": 30, "address": {"street": "123 Main St", "city": "New York"}}';

// Decode the JSON data into a PHP array
$data = json_decode($json_data, true);

// Extract specific data from nested arrays
$person_name = $data['name'];
$person_city = $data['address']['city'];

echo "Name: " . $person_name . "<br>";
echo "City: " . $person_city;