How can the presence of numerical keys in arrays impact the functionality of PHP code?

When numerical keys are present in arrays, it can cause unexpected behavior in PHP code, especially when iterating over arrays using functions like foreach. To ensure the correct functionality, it's important to use associative keys in arrays when iterating over them.

// Incorrect way with numerical keys causing unexpected behavior
$array = [1, 2, 3];
foreach ($array as $value) {
    echo $value . "\n";
}

// Correct way using associative keys
$array = ['key1' => 1, 'key2' => 2, 'key3' => 3];
foreach ($array as $key => $value) {
    echo $value . "\n";
}