How can you optimize loop performance in PHP for better efficiency?

To optimize loop performance in PHP for better efficiency, you can reduce the number of iterations by using foreach loops instead of traditional for loops whenever possible. Additionally, you can minimize the amount of work done within the loop body by moving any calculations or operations outside of the loop that do not need to be repeated for each iteration.

// Example of optimizing loop performance in PHP
$items = [1, 2, 3, 4, 5];

// Inefficient loop
foreach ($items as $item) {
    $result = $item * 2;
    echo $result;
}

// Optimized loop
$multiplier = 2;
foreach ($items as $item) {
    $result = $item * $multiplier;
    echo $result;
}