我想在forms
内parent form
生成2 foreach loop
。很奇怪看到first form
没有生成,parent form
在子表单生成之前就结束了。为什么会这样?
<form action="" method="POST">
<?php
$array = [1,2];
foreach ($array as $arr) {
echo '<form action="" id="'.$arr.'" method="POST">
<input type="text" placeholder="hello">
</form>';
}
?>
</form>
它应该是这样的:
<form action="" method="POST">
<form action="" id="1" method="POST">
<input type="text" placeholder="hello">
</form>
<form action="" id="2" method="POST">
<input type="text" placeholder="hello">
</form>
</form>
它看起来像这样:
<form action="" method="POST">
<input type="text" placeholder="hello">
</form>
<form action="" id="2" method="POST">
<input type="text" placeholder="hello">
</form>
答案 0 :(得分:0)
删除短语法数组。尝试将$array = [1,2];
替换为$array = array(1,2);
输入结束斜杠。 <input type="text" placeholder="hello">
的{{1}}
OR
<input type="text" placeholder="hello"/>