What are some best practices for optimizing PHP code for performance?

One best practice for optimizing PHP code for performance is to minimize the use of unnecessary loops and function calls. This can be achieved by storing the results of expensive function calls in variables and reusing them instead of calling the function multiple times. Example:

// Bad practice - calling the same function multiple times
$result = expensiveFunction();
echo $result;
echo $result;
echo $result;

// Good practice - store the result in a variable and reuse it
$result = expensiveFunction();
echo $result;
echo $result;
echo $result;