Modifying an array with foreach()
<?
$meals = array('A' => 1,
'B' => 4.95,
'C' => 3.00,
'D' => 6.50);
foreach ($meals as $dish => $price) {
$meals[$dish] = $meals[$dish] * 2;
}
foreach ($meals as $dish => $price) {
printf("The new price of %s is \$%.2f.\n",$dish,$price);
}
?>
Related examples in the same category