What are some common pitfalls when working with arrays in PHP, as seen in the provided code snippet?

One common pitfall when working with arrays in PHP is accessing array elements without checking if they exist, which can lead to "Undefined index" notices or errors. To avoid this issue, always check if the key exists in the array before trying to access it. This can be done using functions like isset() or array_key_exists(). Example fix:

// Original code snippet
$fruits = array("apple", "banana", "orange");
echo $fruits[3]; // This will throw an "Undefined index" notice

// Fixed code snippet
$fruits = array("apple", "banana", "orange");
if (isset($fruits[3])) {
    echo $fruits[3];
} else {
    echo "Element does not exist";
}