What are potential pitfalls when working with arrays in PHP, and how can they be avoided?

One potential pitfall when working with arrays in PHP is not checking if an array key exists before trying to access it. This can lead to errors if the key does not exist, causing your script to break. To avoid this, you can use the `isset()` function to check if a key exists before accessing it.

// Potential pitfall: accessing an array key without checking if it exists
$array = ['key' => 'value'];

// This will throw an error if the key does not exist
$value = $array['non_existent_key'];

// Avoiding the pitfall by checking if the key exists
if(isset($array['non_existent_key'])) {
    $value = $array['non_existent_key'];
} else {
    $value = 'default_value';
}