What are the potential pitfalls of using nested while loops in PHP code for control flow?

Using nested while loops can lead to complex and hard-to-read code, making it difficult to debug and maintain. It can also result in performance issues if not optimized properly. To avoid these pitfalls, consider refactoring the code to use alternative control structures like foreach loops or breaking down the logic into smaller, more manageable functions.

// Example of refactoring nested while loops using foreach loop

$array1 = [1, 2, 3];
$array2 = ['a', 'b', 'c'];

foreach ($array1 as $value1) {
    foreach ($array2 as $value2) {
        // do something with $value1 and $value2
    }
}