I am trying to generate a drop down menu for my products page on a website.
What I want to do is make it so that if the $colors = "Yellow, Green, Blue" then php will go through and every time there is a comma it will write the color into an array which can be used to make a dropdown menu.
Any Help?
breaking a field into sections
Moderator: General Moderators
Try this:
Code: Select all
<?php
$colors = "Yellow,Green,Blue";
$colorArray = explode(",",$colors);
?>
<select name="color">
<?php
while (list($index,$color) = each ($colorArray))
{
echo "<option value="$color">$color</option>";
}
?>
</select>