mercredi 11 février 2015

I am trying to check to see if a value is in an array

I am trying to populate checkbox and then check them if a value is in an array.

Here is the code. I ran print_r on the $_SESSION arrays and I am representing them here



$_SESSION['inservice']['inservicepositionclasses']=Array
(
[0] => Array
(
[inservid] => 16
[positionclassid] => 1
)

);

$_SESSION['positionclasses']['classes'] = Array
(
[0] => Array
(
[positionclassid] => 4
[positionclass] => Cardiology technician
)

[1] => Array
(
[positionclassid] => 3
[positionclass] => CNA
)

[2] => Array
(
[positionclassid] => 2
[positionclass] => LPN
)

[3] => Array
(
[positionclassid] => 1
[positionclass] => RN
)

);


Here is the foreach loop to set up divs with labels and checkboxes.



<?foreach($_SESSION['positionclasses']['classes'] as $positonclass){
$checked='';
if(is_array($_SESSION['inservice']['inservicepositionclasses'])) {
if(in_array($positonclass['positionclassid'],$_SESSION['inservice'}['inservicepositionclasses'])){
$checked = 'checked="checked"';
}
}?>
<div class="width330">
<label for="positionclassids" class="width250 inlineblock"><?echo $positonclass['positionclass'];?></label>
<input type="checkbox" name="positionclassids[]" disabled="disabled" <?echo $checked;?> value="<?echo $positonclass['positionclassid'];?>" />
</div>


It doesn't seem to be working as the checkbox with the label RN that should be getting checked and it isn't. Does anyone see anything wrong with this logic?





Aucun commentaire:

Enregistrer un commentaire