vendredi 1 juin 2018

PHP - Checking checkboxes if their value is in array

I have 2 arrays, I take 1 string out of the first array and check if its in the second array, if it is then the checkbox is already checked. My code does check the checkbox but it also creates an unchecked version of the same checkbox. My if statement is in a foreach loop so the problem might be in the order, but cant seem to figure it out.

My code:

          <?php foreach ($zamestnanec_item as $key => $value):?>
                         [Other codes here]
                        <?php foreach ($myukony_item as $key => $value3):
                        if(in_array($value['Nazov'],$value3)): ?>
                        <input type="checkbox" name="ukony[]" value="<?php echo $value['ID_ukon'] ?>" checked="checked"><?php echo $value['Nazov'] ?>
                        <?php else: ?>
                        <input type="checkbox" name="ukony[]" value="<?php echo $value['ID_ukon'] ?>" ><?php echo $value['Nazov'] ?>
                        <?php endif; ?>
                       <?php endforeach;?>
          <?php endforeach;?>




Aucun commentaire:

Enregistrer un commentaire