What are some common pitfalls to watch out for when manipulating keys and values in multidimensional arrays in PHP?

One common pitfall when manipulating keys and values in multidimensional arrays in PHP is accidentally overwriting existing data when assigning new values. To avoid this, always check if a key already exists before assigning a new value to it. Another pitfall is not properly accessing nested arrays, which can lead to errors or unexpected behavior. Make sure to correctly navigate through the nested arrays using the appropriate keys.

// Check if a key exists before assigning a new value
if (!isset($array['key'])) {
    $array['key'] = 'value';
}

// Accessing nested arrays
$nestedArray = [
    'first' => [
        'second' => 'value'
    ]
];

echo $nestedArray['first']['second'];