Php 将数组值与嵌套while循环中的输入字段匹配
这真是一个愚蠢的问题。我不知道我是怎么得到这个的,但我得到了。 我有一个数组,我想把数组值和while循环中的复选框匹配起来。那么这怎么可能呢Php 将数组值与嵌套while循环中的输入字段匹配,php,arrays,multidimensional-array,while-loop,Php,Arrays,Multidimensional Array,While Loop,这真是一个愚蠢的问题。我不知道我是怎么得到这个的,但我得到了。 我有一个数组,我想把数组值和while循环中的复选框匹配起来。那么这怎么可能呢 //Array that i want to match with checkbox $filter = explode(',', $getproduct->specification_filter); <table class="ta
//Array that i want to match with checkbox
$filter = explode(',', $getproduct->specification_filter);
<table class="table" style="background-color: white;">
<tbody>
<?php
while($fch = $allfilter->fetch_array()){
?>
<tr>
<th><?=$fch[2]?></th>
<?php
$sqlbv="SELECT * FROM product_filter where idd='$fch[4]'";
$resultbv=$conn->query($sqlbv);
while($rowbv = $resultbv->fetch_array()){
?>
<td>
<label class="ckbox ckbox-danger">
<input type="checkbox" value="<?=$rowbv[0]?>" name="pfilter[]">
<span> <?=$rowbv[3]?></span>
</label>
</td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
//要与复选框匹配的数组
$filter=explode(“,”,$getproduct->specification\u filter);
只需使用in_array()来检查这一点。如果其为真且标记为选中
<input type="checkbox" value="<?=$rowbv[0]?>" name="pfilter[]" <?php echo in_array($rowbv[0],$filter) ? 'checked="checked"' : '';?>>
>
希望这能对您有所帮助。只需使用in_array()进行检查。如果其为真且标记为选中
<input type="checkbox" value="<?=$rowbv[0]?>" name="pfilter[]" <?php echo in_array($rowbv[0],$filter) ? 'checked="checked"' : '';?>>
>
希望这能对您有所帮助。因为您的$filter
是一个数组,在数组中使用
<input type="checkbox" value="<?=$rowbv[0]?>" <?= in_array($rowbv[0], $filter)? 'checked':'' ?> name="pfilter[]">
name=“pfilter[]”
有关更多详细信息,请参阅。,因为您的$filter
是一个数组,请在\u数组中使用
<input type="checkbox" value="<?=$rowbv[0]?>" <?= in_array($rowbv[0], $filter)? 'checked':'' ?> name="pfilter[]">
name=“pfilter[]”
有关更多详细信息,请参见。在输入复选框中,您可以选中添加属性“已选中”
为此,你可以写作
< input type="checkbox" < ?=($rowbv[0] ? 'checked' : '')?> name="pfilter[]"/>
name=“pfilter[]”/>
否则
name=“pfilter[]”/>
在输入复选框中,您可以选中添加属性“已选中”
为此,你可以写作
< input type="checkbox" < ?=($rowbv[0] ? 'checked' : '')?> name="pfilter[]"/>
name=“pfilter[]”/>
否则
name=“pfilter[]”/>
您的意思是说,如果$rowbv[0]
将在$filter
数组中可用,那么是否要选中该复选框?是。我尝试在输入类型中使用foreach复选框。它好吗?抱歉,但我说的您想检查所选复选框值是否为有效条目是否正确?是吗?不,肖克宁。如果$rowbv[0]在$filter数组中可用,那么我想选中该复选框。您的意思是说,如果$rowbv[0]
在$filter
数组中可用,那么您想选中该复选框吗?是的。我尝试在输入类型中使用foreach复选框。它好吗?抱歉,但我说的您想检查所选复选框值是否为有效条目是否正确?是吗?不,肖克宁。如果$rowbv[0]在$filter数组中可用,那么我想选中该复选框。