What are the potential pitfalls of using assignment operators within conditional statements in PHP loops?

Using assignment operators within conditional statements in PHP loops can lead to unintended behavior or bugs. This is because assignment operators can inadvertently change the value of variables being used in the condition, potentially causing the loop to behave unexpectedly. To avoid this issue, it's best to separate assignment operations from conditional statements within loops.

// Incorrect way of using assignment operators within conditional statements in a loop
$counter = 0;
while ($counter = 5) {
    echo $counter;
    $counter++;
}

// Correct way of separating assignment operations from conditional statements in a loop
$counter = 0;
while ($counter < 5) {
    echo $counter;
    $counter++;
}