What are potential pitfalls when using arrays in PHP and how can they be avoided?

One potential pitfall when using arrays in PHP is not checking if an array key exists before accessing it, which can result in errors or unexpected behavior. To avoid this, you can use the `isset()` function to check if a key exists before trying to access it.

// Check if array key exists before accessing it
if (isset($array['key'])) {
    // Access the array key
    $value = $array['key'];
    // Do something with $value
} else {
    // Handle the case where the key doesn't exist
    echo 'Key does not exist';
}