Combine two arrays as key => value pairs in php4
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>";
}
?>
Home - Apache - Ubuntu - MySQL - PHP - Misc

The Ubuntu Counter Project - user number # 17415
Updated on: 2008-01-19 07:22:18