How does the use of nested loops in the PHP script contribute to the generation of tip rows?

Using nested loops in the PHP script allows us to iterate over multiple arrays to generate tip rows for each combination of meal and tip percentage. The outer loop iterates over the meals array, while the inner loop iterates over the tip percentages array. Within the nested loops, we can calculate the tip amount for each combination and generate a row in the tip table.

$meals = ['Breakfast', 'Lunch', 'Dinner'];
$tipPercentages = [10, 15, 20];

echo '<table>';
echo '<tr><th>Meal</th><th>Tip Percentage</th><th>Tip Amount</th></tr>';

foreach ($meals as $meal) {
    foreach ($tipPercentages as $tipPercentage) {
        $tipAmount = $mealPrice * ($tipPercentage / 100);
        echo '<tr><td>' . $meal . '</td><td>' . $tipPercentage . '%</td><td>$' . number_format($tipAmount, 2) . '</td></tr>';
    }
}

echo '</table>';