What are the potential pitfalls of manipulating arrays in PHP?

One potential pitfall of manipulating arrays in PHP is not properly checking if a key exists before trying to access or modify it. This can lead to errors or unexpected behavior if the key does not exist in the array. To avoid this issue, it is recommended to use array_key_exists() function to check if a key exists before performing any operations on it.

// Check if a key exists before accessing or modifying it
if (array_key_exists('key', $array)) {
    // Perform operations on the key
    $array['key'] = 'new value';
} else {
    // Key does not exist, handle accordingly
}