What are some common pitfalls when trying to add a new key to a nested array in PHP?

When trying to add a new key to a nested array in PHP, a common pitfall is not properly referencing the nested array when assigning the new key. To solve this, you need to access the nested array using the correct keys and then assign the new key to it.

// Incorrect way to add a new key to a nested array
$nestedArray = [
    'key1' => [
        'key2' => 'value'
    ]
];

// This will not add the new key to the nested array
$nestedArray['key1']['key3'] = 'new value';

// Correct way to add a new key to a nested array
$nestedArray['key1']['key3'] = 'new value';