What are some common mistakes that developers make when manipulating arrays in PHP, and how can they be avoided?

One common mistake developers make when manipulating arrays in PHP is not checking if a key exists before trying to access it. This can result in "Undefined index" notices or errors. To avoid this, always use functions like `isset()` or `array_key_exists()` to check if a key exists before trying to access it.

// Incorrect way - accessing key without checking if it exists
$array = ['key' => 'value'];
echo $array['non_existent_key']; // This will throw an error

// Correct way - check if key exists before accessing it
if (isset($array['non_existent_key'])) {
    echo $array['non_existent_key'];
} else {
    echo 'Key does not exist';
}