问题描述
我有一个像
$srr = 'Mechanical engineering was at the heart of {} Taylor's theorizing,providing {} the context for its development,the world view by which it was sustained and,finally,the justification for its widespread application.';
我需要将每个{}
转换为HTML select
,并且option
的值将是动态的,我将从数据库中获取该值。
我的问题是,当我尝试将{}
替换为选择框时,
str_replace
不允许我添加foreach循环。
我正在使用array_chunk() ( $fouroptions = array_chunk($options,4); )
将选项分为4个,
并且我想将{}
替换为使用array_chunk()
获得的选项值。
我得到了数组
(
[0] => Array
(
[0] => A
[1] => B
[2] => C
[3] => D
)
[1] => Array
(
[0] => E
[1] => F
[2] => G
[3] => H
)
[2] => Array
(
[0] => I
[1] => J
[2] => K
[3] => L
)
)
这是我的php代码:
$fouroptions = array_chunk($options,4);
$loop = count($fouroptions);
for ($row = 0; $row < $loop; $row++)
{
$testselect= "<select>";
for ($col = 0; $col < 4; $col++)
{
$testselect .= "<option>".$fouroptions[$row][$col]."</option>";
}
$testselect .= "</select>";
echo $string = str_replace("{}",$testselect,$quiz_question['title']);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)