我有5个复选框,如果数组元素与复选框值相同,则我的数组有3个元素,然后选中该复选框,但它应该只打印一次
<?php
$selvals = array("Manhattan", "Bronx", "Brooklyn");
$myArray = explode(',', $selvals);
foreach($myArray as $i)
{
?>
<label class="checkbox-inline"><input type="checkbox" <?php if($i == "Manhattan"){ echo 'checked="checked"';}?> name="manhattan" value="Manhattan" >Manhattan</label>
<label class="checkbox-inline"><input type="checkbox" <?php if($i == "Bronx"){ echo 'checked="checked"';}?> name="bronx" value="Bronx" >Bronx</label>
<label class="checkbox-inline"><input type="checkbox" <?php if($i == "Brooklyn"){ echo 'checked="checked"';}?> name="brooklyn" value="Brooklyn" >Brooklyn</label>
<label class="checkbox-inline"><input type="checkbox" <?php if($i == "Queens"){ echo 'checked="checked"';}?> name="queen" value="Queens" >Queens</label>
<label class="checkbox-inline"><input type="checkbox" <?php if($i == "Staten Island"){ echo 'checked="checked"';}?> name="staten" value="Staten Island" >Staten Island</label>
<?php
}
?>
答案 0 :(得分:1)
我认为你的代码应该是这样的: - :)
upload.py
答案 1 :(得分:0)
explode
函数的第二个参数应该是一个字符串。但是您不需要它,只需删除爆炸声明并将$myArray
替换为循环中的$selvals
。
$selvals = array("Manhattan", "Bronx", "Brooklyn");
foreach ($selvals as $i)
^^^^^^^