What are the advantages and disadvantages of using a for loop instead of a while loop in PHP?

When deciding between using a for loop or a while loop in PHP, it is important to consider the specific requirements of the task at hand. For loops are ideal for situations where you know the exact number of iterations needed, as they allow you to define the initialization, condition, and increment all in one line. On the other hand, while loops are more flexible and can be used when the number of iterations is not predetermined.

// Example of using a for loop in PHP
for ($i = 0; $i < 5; $i++) {
    echo "Iteration: $i <br>";
}