What are potential pitfalls when using array manipulation in PHP, as seen in the provided code snippet?

One potential pitfall when using array manipulation in PHP is not checking if the array key exists before accessing it. This can lead to "Undefined index" notices or errors. To solve this issue, you can use the isset() function to check if the key exists before trying to access it.

// Potential pitfall: accessing array key without checking if it exists
$colors = array("red", "green", "blue");
if ($colors['0']) {
    echo $colors['0']; // This will work fine
}

if ($colors['3']) {
    echo $colors['3']; // This will throw an "Undefined index" notice
}

// Fix: Check if the key exists before accessing it
if (isset($colors['3'])) {
    echo $colors['3']; // This will not throw an error
}