What is the difference in output between using a for loop and a foreach loop to iterate over an array in PHP?

When iterating over an array in PHP, the main difference between using a for loop and a foreach loop is in how the loop is structured. A for loop requires you to manually set the iteration variable and condition for looping, while a foreach loop automatically iterates over each element in the array without the need for an explicit index. Here is a code snippet that demonstrates the difference between using a for loop and a foreach loop to iterate over an array in PHP:

// Using a for loop
$array = [1, 2, 3, 4, 5];
for ($i = 0; $i < count($array); $i++) {
    echo $array[$i] . " ";
}

// Using a foreach loop
$array = [1, 2, 3, 4, 5];
foreach ($array as $value) {
    echo $value . " ";
}