What are some best practices for optimizing PHP code performance when manipulating arrays?

When manipulating arrays in PHP, it is important to optimize the code for performance to ensure efficient execution. One best practice is to avoid unnecessary loops and function calls when working with arrays. Instead, use built-in array functions like array_map(), array_filter(), and array_reduce() to manipulate arrays efficiently.

// Example of optimizing PHP code performance when manipulating arrays
// Using array_map() to manipulate array elements efficiently

// Original array
$numbers = [1, 2, 3, 4, 5];

// Doubling each element in the array using array_map()
$doubledNumbers = array_map(function($num) {
    return $num * 2;
}, $numbers);

// Output the doubled numbers
print_r($doubledNumbers);