What are some best practices for optimizing PHP code that involves looping through arrays?

When optimizing PHP code that involves looping through arrays, it's important to minimize the number of iterations and reduce unnecessary operations within the loop. One way to achieve this is by pre-calculating values outside the loop whenever possible and using efficient looping constructs like foreach instead of traditional for loops.

// Example of optimizing PHP code with array iteration
$numbers = [1, 2, 3, 4, 5];
$total = 0;

// Inefficient approach
foreach ($numbers as $number) {
    $total += $number * 2;
}

// Optimized approach
$multiplier = 2;
foreach ($numbers as $number) {
    $total += $number * $multiplier;
}