I'm current'y having 2 variables, for $arrAns
, it contains the different answer that the user select for a checkbox. Example for $arrAns will be 1,2,3. And for $arr
, it's the option variable which contains all the options that the question have. Example of $arr
will be 1,2,3,4,5,6.
Here's the code whereby I trying to compare, if $arrAns == $arr, then the checkbox input will be "checked". else, it will be leave as blank.
But when I tried using the codes, if user's selection is 1,2,3. It works. But if user selects 2,3,4 non of the options will be "checked". And if user selects 1,3,4 only option 1 will be "checked".
Is there something wrong with the logic in between? In need of help, Thank you!
<?php if ($arrAns[$i] == $arr) {
?>
<input type="checkbox" name="<?php echo 'qns' . $qID; ?>[]" value="<?php echo $arr; ?>" class="required" checked/> <?php echo $arr; ?><br/>
<?php } else { ?>
<input type="checkbox" name="<?php echo 'qns' . $qID; ?>[]" value="<?php echo $arr; ?>" class="required"/> <?php echo $arr; ?><br/>
<?php
} ?>