What are the best practices for looping through arrays and manipulating values in PHP?

When looping through arrays in PHP, it is important to use the correct loop structure (such as foreach) to efficiently iterate over each element. To manipulate values within the array, you can directly access and modify the value at a specific index using array indexing.

// Example of looping through an array and manipulating values
$array = [1, 2, 3, 4, 5];

foreach ($array as $key => $value) {
    $array[$key] = $value * 2; // Manipulate the value by doubling it
}

print_r($array); // Output the modified array