What are the potential pitfalls of combining a foreach loop and a for loop in PHP?

Combining a foreach loop and a for loop in PHP can lead to unexpected behavior or errors, as they both iterate over arrays in different ways. To avoid potential pitfalls, it's best to stick to using one type of loop for iterating over arrays. If you need to use both types of loops, consider converting the array to a numerical indexed array before using the for loop.

// Example of converting an associative array to a numerical indexed array before using a for loop
$associativeArray = ['a' => 1, 'b' => 2, 'c' => 3];

// Convert associative array to numerical indexed array
$numericArray = array_values($associativeArray);

// Use a for loop to iterate over the numerical indexed array
for ($i = 0; $i < count($numericArray); $i++) {
    echo $numericArray[$i] . "\n";
}