I have an array: $categories = array("item1", "item2", "item3");
I also have three arrays: $item1Array = array("hi", "items");, $item2Array = array("hi", "items");, $item3Array = array("hi", "items");
I stated a foreach like this:
foreach ($categories as &$value) {
echo "<optgroup label='" . $value . "'>';
$nextArray = $value . "Array";
foreach($nextArray as &$nextValue) {
echo "<option value='" . $nextValue . "'>" . $nextValue . "</option>";
}
}
but it get an error Warning: invalid argument supplied for foreach().
Is there a way I can achieve this?
Of course, but as you can clearly see from the syntax highlighting of your post, you used a
'instead of a"at the end of the “optgroup” line.Also, you could just use a nested array: