【发布时间】:2019-05-29 14:28:48
【问题描述】:
<?php
if(isset($_POST['feature'])){
if(!empty($_POST['test'])){
foreach($_POST['test'] as $selected){
var_dump($_POST['test']);
}
}
}
?>
<form action="" method="POST">
<?php
$query = $products->findAll();
foreach($query as $row){
if($row['featured'] == 'Yes'){
echo "<label for='featured'>" . $row['p_name'] . " </label> <input type='checkbox' name='test[]' value = 'Yes' checked>";
}
else
{
echo "<label for='featured'>" . $row['p_name'] . " </label> <input type='checkbox' name='test[]' value ='No'>";
}
}
?>
<input type="submit" name="feature" value="Feature">
</form>
我有 5 件产品被“选中”。当我循环查找选择的内容时,我得到了 5 个不同的数组和 5 个字符串?我看不出哪里出错了,它应该返回 5 个数组,其中只有一个“是”字符串以显示它已被选中?
【问题讨论】:
标签: php arrays loops for-loop each