How can a for loop be used in PHP to perform a calculation a specific number of times?

To perform a calculation a specific number of times in PHP, you can use a for loop. The for loop allows you to specify the number of iterations you want to perform, making it ideal for repetitive tasks. Within the loop, you can perform the calculation and update any necessary variables accordingly.

<?php
// Perform a calculation 5 times
$total = 0;
for ($i = 0; $i < 5; $i++) {
    $total += $i;
}
echo "The total sum is: $total";
?>