What are the potential pitfalls of using nested while loops in PHP?

Using nested while loops in PHP can lead to performance issues and make the code harder to read and maintain. It can also increase the likelihood of infinite loops if not properly controlled. To avoid these pitfalls, consider using alternative looping structures like foreach loops or breaking out of loops when necessary.

// Example of using a foreach loop instead of nested while loops
$array = [1, 2, 3, 4, 5];

foreach ($array as $element) {
    echo $element . "\n";
}