I need some help with arrays!

Hi, I would like to add a description according to the color of the car in another array, like this:

$cars = array(
        array("Make"=>"Toyota", "Model"=>"Corolla", "Color"=>"White", "Mileage"=>24000, "Status"=>"Sold", "Description" => ""),
        array("Make"=>"Toyota", "Model"=>"Camry", "Color"=>"Black", "Mileage"=>56000, "Status"=>"Available", "Description" => ""),
        array("Make"=>"Honda", "Model"=>"Accord", "Color"=>"White", "Mileage"=>15000, "Status"=>"Sold", "Description" => ""),
        array("Make"=>"Nissan", "Model"=>"Juke", "Color"=>"Red", "Mileage"=>4500, "Status"=>"Sold", "Description" => ""));

$color = array(
         array("Black" => "Night"),
         array("Red" => "Love"),
         array("White" => "Sky"));

echo "<table cellpadding='10' cellspacing'10' border='1'>";
echo "<tr> <th>Make</th> <th>Model</th> <th>Color</th> <th>Mileage</th> <th>Status</th> <th>Description</th> </tr>";
foreach($result as $car) {
    echo "<tr> <td>$car[Make]</td> <td>$car[Model]</td> <td>$car[Color]</td> <td>$car[Mileage]</td> <td>$car[Status]</td> </tr>";
echo "</table>";


you may wan to use the color as the key, so you can access the description by the car’s color.

Sponsor our Newsletter | Privacy Policy | Terms of Service