I have the following array and PHP code - this adds an option
to a drop down list and works fine but this is one drop down list.
However, what I would like to achieve is for a separate drop down list to be created for each of the unique values in the array [0]
in the array.
So based on the array below there would be three drop down lists, one for ACME, one for EDNON and one for VALUE and each list would be populated with information already included in the PHP code below.
Array
Array (
[4f5hfgb] => Array (
[0] => ACME
[1] => 4f5hfgb
[2] => Aberdeen
)
[sdf4ws] => Array (
[0] => ACME
[1] => sdf4ws
[2] => Birmingham
)
[dfgdfg54] => Array (
[0] => EDNON
[1] => dfgdfg54
[2] => Birmingham
)
[345bfg] => Array (
[0] => EDNON
[1] => 345bfg
[2] => Birmingham
)
[345fgfd] => Array (
[0] => VALVE
[1] => 345fgfd
[2] => Birmingham
)
)
PHP
echo "
<span class='Question SelectBox'>
<span class='qnum noshow'></span>
<span class='qtext'>Option</span>
<span class='shown'>
<select class='combobox' id='option' name='option' data-placeholder=\"Option...\" '>
<option value=\"\">Option...</option>";
foreach ($tmp as $value) {
echo "<option name='".$value[0]."' value='".$value[1]."'>".$value[2]."</option>";
}
echo"</select>
</span>
</span>
<span class='clearfix'></span>";
Attempted code
I have tried modifying the code but this only produces one drop down and the options are duplicated:
foreach ($tmp as $value) {
if($value[0]=='ACME'){
echo "<option name='".$value[0]."' value='".$value[1]."'>".$value[2]."</option>";echo "<option name='".$value[0]."' value='".$value[1]."'>".$value[2]."</option>";
}
}
I'm struggling to understand if this is actually possible. Any advice, feedback and suggestions welcomed.