How can you manipulate data in an array before outputting it in a loop?

When outputting data from an array in a loop, you can manipulate the data before displaying it by using array functions or custom logic within the loop. For example, you can modify the values, filter out certain elements, or format the data in a specific way before outputting it. This can be useful for displaying data in a desired format or performing calculations on the data before displaying it.

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

// Loop through the array and double each number before outputting it
foreach ($numbers as $number) {
    $doubledNumber = $number * 2;
    echo $doubledNumber . " ";
}