What are the potential pitfalls of including PHP functions within a loop, and how can they be avoided?

Including PHP functions within a loop can lead to decreased performance due to the function being called multiple times unnecessarily. This can be avoided by storing the result of the function outside of the loop and then referencing that stored value within the loop.

// Example of avoiding calling a function within a loop
$result = myFunction();

for ($i = 0; $i < 10; $i++) {
    // Use the stored result instead of calling the function again
    echo $result;
}

function myFunction() {
    // Function logic here
    return "Function result";
}