What potential pitfalls can arise 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 a notice or warning. To avoid this, you can use functions like isset() or array_key_exists() to check if an index exists before accessing it.

// Example of checking if an index exists before accessing it
$myArray = ['apple', 'banana', 'cherry'];

if (isset($myArray[1])) {
    echo $myArray[1]; // Output: banana
} else {
    echo 'Index does not exist';
}