How can the syntax for accessing values in nested arrays be optimized in PHP?

When accessing values in nested arrays in PHP, the syntax can become cumbersome and hard to read, especially if there are multiple levels of nesting. One way to optimize this is by using the null coalescing operator (??) along with the null-safe object operator (->) to safely access nested array values without the need for multiple isset() checks.

// Nested array
$data = [
    'user' => [
        'name' => 'John Doe',
        'age' => 30,
        'address' => [
            'street' => '123 Main St',
            'city' => 'New York',
            'country' => 'USA'
        ]
    ]
];

// Optimized syntax for accessing nested array values
$street = $data['user']['address']['street'] ?? null;
$city = $data['user']['address']['city'] ?? null;
$country = $data['user']['address']['country'] ?? null;

echo $street . ', ' . $city . ', ' . $country;