How can the order of operators impact the functionality of storing loop results in a variable in PHP?

The order of operators can impact the functionality of storing loop results in a variable in PHP when the assignment operator (=) is used before the operator that performs the loop iteration. This can lead to unexpected results or errors as the loop results may not be stored correctly in the variable. To solve this issue, make sure to use the correct order of operators by first performing the loop iteration and then assigning the result to the variable.

// Incorrect way: assigning before performing the loop iteration
$sum = 0;
for ($i = 1; $i <= 10; $i++) 
    $sum = $sum + $i; // Incorrect order of operators

echo $sum; // Output will not be correct

// Correct way: performing the loop iteration before assigning to the variable
$sum = 0;
for ($i = 1; $i <= 10; $i++) {
    $sum = $sum + $i; // Correct order of operators
}

echo $sum; // Output will be correct