I have the following code:
foreach ($row as $item) {
if (!in_array($item['login_id'], $tmp)) {
$tmp[] = $item['brand'];
$tmp[] = $item['login_id'];
$tmp[] = $item['name'];
}
}
This provides the following output:
array(408) {
[0]=> string(4) "ABC"
[1]=> string(8) "r4ft6tg7"
[2]=> string(8) "Aberdeen"
[3]=> string(4) "ABC"
[4]=> string(8) "1ws3edft"
[5]=> string(18) "Birmingham Airport"
[6]=> string(4) "DDD"
[7]=> string(8) "bgt6yhnj"
[8]=> string(27) "Birmingham City"...}
I am trying to then loop through this array and add them to a dropdown using the following:
$a = 0;
$b = 1;
$c = 2;
foreach ($tmp as $value) {
echo "<option name='".$value[$a]."'
value='".$value[$b]."'>
".$value[$c]."
</option>";
$a=$a+3;
$b=$b+3;
$c=$c+3;
}
However the output is most odd:
<option name='I' value='b'>i</option>
The output I expected and need is:
<option name='ABC' value='r4ft6tg7'>Aberdeen</option>
Any suggestions, feedback on where I am going wrong would be appreciated.
$value
is a string, so accessing$value[$x]
will yield whatever character is at that index in the string...what are you trying to accomplish exactly? What are$a
,$b
and$c
for? – Clive Jul 6 at 11:53option
output. So for example,<option name='ABC' value='r4ft6tg7'>Aberdeen</option>
– Homer_J Jul 6 at 11:57