php5 has a function to combine two arrays using the array_combine() function. Unfortunately it's a bit more difficult in php4.
The code below could be used to update a row of text boxes in a shopping cart, using the product id and new qty selected by the customer.
| PHP Code: |
<?php
$food = array('Eggs', 'Rashers of Bacon', 'Sausages', 'Pieces of Fried Bread');
$qty = array('2', '4', '8', '4');
$meal = array();
$i = 0;
while($i < count($food)) {
$meal[$food[$i]] = $qty[$i];
$i++;
}
foreach($meal as $qty => $food) {
echo $qty . " ". $food ."<br>";
}
?>
|
|