I have an array that looks like this:
Array (
[0] => Array ( [denumireObiect] => Telefon )
[1] => Array ( [denumireObiect] => Laptop )
[2] => Array ( [denumireObiect] => Tableta )
[3] => Array ( [denumireObiect] => Obiect )
)
I am trying to take all of those words and make them options for a <select> tag.
This is the code I am using for that:
foreach ($result as $i) {
echo '<option value = ', $result[$i],'>', $result[$i], '</option>';
}
This paragraph gives me Illegal offset type error.
This is a var_dump($result) result.
array(4) {
[0]=> array(1) {
["denumireObiect"]=> string(7) "Telefon"
}
[1]=> array(1)
{ ["denumireObiect"]=> string(6) "Laptop" }
[2]=> array(1) {
["denumireObiect"]=> string(7) "Tableta"
}
[3]=> array(1) {
["denumireObiect"]=> string(6) "Obiect" }
}
...
EDIT:
I have tried doing it like this:
foreach ($result as $i => $val) {
echo '<option value = ', $i,'>', $i, '</option>';
}
and it returns 0, 1, 2, 3
Any help is appreciated!
var_dumpresult and tried a new way to do this. Hope it helps!,as a string concatenator work? AFAIK you need to use.(php.net/manual/en/language.operators.string.php), but maybe that's because I'm in the US.echo "test","ing";vsecho "test"."ing";- I would expect the first to throw an error, while the second would outputtesting.echopage: php.net/manual/en/function.echo.php