I have two arrays and below is the output. The first array is my all the list and the second I am getting by the user selected.
$specification=getgeneralSpecifications($pdo); // getting below array
Array(
[0] => Array
(
[sp_id] => 1
[specifications_name] => example 1
)
[1] => Array
(
[sp_id] => 2
[specifications_name] => example 2
)
[2] => Array
(
[sp_id] => 3
[specifications_name] => example 3
)
[3] => Array
(
[sp_id] => 4
[specifications_name] => example 4
)
[4] => Array
(
[sp_id] => 5
[specifications_name] => example 5
)
[5] => Array
(
[sp_id] => 6
[specifications_name] => example 6
)
)
$getgeneral = explode(",",$info['developerprofile']['general_Specifications']); // getting below output
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
I have to display all the lists from the database and I have checked the check box depending on the second array value getting the form database.
I tried the below code and I am getting the output but missing one value.
I mean if I have array 1,2,3,4
then I am getting on 1,2,3
<?php
$specification=getgeneralSpecifications($pdo);
$getgeneral = explode(",",$info['developerprofile']['general_Specifications']);
foreach ($specification as $key=> $row) {
$checked="";
if(in_array($key, $getgeneral)){
$checked="checked";
}
?>
<li><label><?php echo $row['specifications_name'];?></label>
<div class="form-check">
<input class="form-check-input custom-checkbox generalsinglecheck" type="checkbox" value="<?php echo $row['sp_id'];?>" name="general_specification[]" <?php echo $checked;?>>
</div>
</li>
<?php } ?>