What are the best practices for optimizing code efficiency when performing repetitive calculations in PHP?

When performing repetitive calculations in PHP, it is important to optimize code efficiency to reduce processing time and improve performance. One way to achieve this is by storing the result of the calculation in a variable and reusing it instead of recalculating the same value multiple times. Additionally, using built-in PHP functions for common operations can also help improve efficiency.

// Example of optimizing code efficiency for repetitive calculations in PHP
$number = 5;

// Inefficient way
for ($i = 0; $i < 1000; $i++) {
    $result = $number * 2;
    // Perform operations with $result
}

// Efficient way
$result = $number * 2;
for ($i = 0; $i < 1000; $i++) {
    // Perform operations with $result
}