What are some potential pitfalls of assigning variables within a loop in PHP?

Assigning variables within a loop in PHP can lead to unintended behavior or errors if the variable is not properly reset or updated in each iteration. To avoid this issue, make sure to initialize or reset the variable before the loop and update it within the loop as needed.

// Initialize or reset the variable before the loop
$sum = 0;

// Loop through an array and update the variable
$numbers = [1, 2, 3, 4, 5];
foreach ($numbers as $number) {
    $sum += $number;
}

echo $sum; // Output: 15