What are the potential pitfalls when working with arrays in PHP?

One potential pitfall when working with arrays in PHP is accessing an index that does not exist, which can result in errors or unexpected behavior. To avoid this, you can use functions like isset() or array_key_exists() to check if an index exists before trying to access it.

// Check if an index exists before accessing it
$array = [1, 2, 3];

if (isset($array[2])) {
    echo $array[2]; // Output: 3
}