Php in_数组不选择从DB收集的复选框的多个值

Php in_数组不选择从DB收集的复选框的多个值,php,Php,当数据库查询具有多个值[永久ID、学员ID卡、ID卡]时,由于未知原因不会对其进行检查 在下面查询以获取复选框 cardtype具有表单中的所有选中值 它只适用于一个复选框字段 1) 永久身份证或学员身份证或身份证 2) 当永久性身份证、学员身份证、仅身份证复选框显示为未选中时 while($row2=mysqli_fetch_array($result2)) { $card_type = explode(',',$row2['cardtype']); if (in_array(

当数据库查询具有多个值[永久ID、学员ID卡、ID卡]时,由于未知原因不会对其进行检查

在下面查询以获取复选框 cardtype具有表单中的所有选中值

它只适用于一个复选框字段 1) 永久身份证或学员身份证或身份证 2) 当永久性身份证、学员身份证、仅身份证复选框显示为未选中时

while($row2=mysqli_fetch_array($result2))
{
    $card_type = explode(',',$row2['cardtype']);
    if (in_array("Permanent ID Card", $card_type))  
    {  
    echo "'Permanent ID Card' found in the array";  
    }  
    <input type="checkbox" name="cardtype" value="Trainee ID Card"<?php if(in_array("Trainee ID Card",$card_type)) echo "checked";?> />Trainee ID Card
    <input type="checkbox" name="cardtype" value="Permanent ID Card"<?php if(in_array("Permanent ID Card",$card_type))  echo "checked";?> />Permanent ID Card
    <input type="checkbox" name="cardtype" value=" ID Card"<?php if(in_array(" ID Card",$card_type))  echo "checked";?> /> ID Card
 }
while($row2=mysqli\u fetch\u数组($result2))
{
$card_type=分解(“,”,$row2['cardtype']);
if(在数组中(“永久身份证”,美元卡类型))
{  
echo“‘永久身份证’在阵列中找到”;
}  
/>永久性居民身份证

请确保if条件中没有空格。此外,在应用
分解后,请修剪空格

$card_type = explode(',',$row2['cardtype']);

$card_type = array_map('trim', $card_type); // Add this line
HTML代码:

<input type="checkbox" name="cardtype" value="Trainee ID Card"<?php if(in_array("Trainee ID Card",$card_type)) echo "checked";?> />Trainee ID Card
<input type="checkbox" name="cardtype" value="Permanent ID Card"<?php if(in_array("Permanent ID Card",$card_type))  echo "checked";?> />Permanent ID Card
<input type="checkbox" name="cardtype" value=" ID Card"<?php if(in_array("ID Card",$card_type))  echo "checked";?> /> ID Card
/>永久身份证

您应该打印您的
$card\u type
并查看您得到了什么:
echo';print\r($card\u type)
您可以检查为该复选框生成的HTML元素吗?我怀疑value=“培训生ID卡”后面没有空格.@JeffreyHitosis有SpacePermant身份证!=数组中y的永久身份证是false@BunkerBoy我已更改,谢谢,但身份证未被选中