Select Dropdown PHP foreach loop with #39;optgroup#39; options(使用“optgroup选项选择下拉 PHP foreach 循环)
问题描述
我有一个带有 PHP 'foreach' 的下拉菜单,我循环遍历它以填充选择选项.这很好用.但是,我想要做的是使用optgroup"选项拥有各种子标签.在我返回的数组中,我有一个蓝色"、绿色"和红色"的类型".如何根据 $album['type'] 将选择选项分组?
I have a dropdown menu with a PHP 'foreach' that I loop through to populate the select options. This works well. However, what I'd like to do is have various sub labels using the "optgroup" option. In my returned array, I have a "type" of "blue", "green" and "red". How can I split the select options up into groups based on the $album['type']?
这是我的代码:
这是我想在 foreach 循环中实现的那种:
This is the kind of thing I'd like to achieve within the foreach loop:
推荐答案
尝试
这篇关于使用“optgroup"选项选择下拉 PHP foreach 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!