What are some common pitfalls to avoid when writing PHP scripts for better performance?

One common pitfall to avoid when writing PHP scripts for better performance is using inefficient loops, such as nested loops or unnecessary iterations. To improve performance, consider using array functions like array_map, array_filter, or array_reduce to manipulate arrays more efficiently.

// Inefficient loop example
$numbers = [1, 2, 3, 4, 5];
$sum = 0;
foreach ($numbers as $number) {
    $sum += $number;
}

// Improved performance using array functions
$numbers = [1, 2, 3, 4, 5];
$sum = array_sum($numbers);