What are potential pitfalls when manipulating arrays in PHP, especially when dealing with associative and numerical keys?

When manipulating arrays in PHP, one potential pitfall is accidentally mixing up numerical and associative keys, which can lead to unexpected behavior or errors. To avoid this, it's important to keep track of the keys you are using and ensure consistency throughout your code.

// Example of manipulating arrays with both numerical and associative keys
$array = array(
    'name' => 'John',
    'age' => 30,
    0 => 'apple',
    1 => 'banana'
);

// Accessing elements using numerical keys
echo $array[0]; // Output: apple

// Accessing elements using associative keys
echo $array['name']; // Output: John