jeudi 29 septembre 2016

Checkbox arrays looping issue

I have 5 checkboxs, my array has 3 elements if the array element same as checkbox value then that checkbox checked but it should print only one time

<?php
$selvals = array("Manhattan", "Bronx", "Brooklyn");
    $myArray = explode(',', $selvals);
    foreach($myArray as $i)
    {

    ?>

    <label class="checkbox-inline"><input type="checkbox" <?php if($i == "Manhattan"){ echo 'checked="checked"';}?> name="manhattan" value="Manhattan" >Manhattan</label>
    <label class="checkbox-inline"><input type="checkbox" <?php if($i == "Bronx"){ echo 'checked="checked"';}?> name="bronx" value="Bronx" >Bronx</label>
    <label class="checkbox-inline"><input type="checkbox" <?php if($i == "Brooklyn"){ echo 'checked="checked"';}?> name="brooklyn" value="Brooklyn" >Brooklyn</label>
    <label class="checkbox-inline"><input type="checkbox" <?php if($i == "Queens"){ echo 'checked="checked"';}?> name="queen" value="Queens" >Queens</label>
    <label class="checkbox-inline"><input type="checkbox" <?php if($i == "Staten Island"){ echo 'checked="checked"';}?> name="staten" value="Staten Island" >Staten Island</label>

    <?php
    }
    ?>




Aucun commentaire:

Enregistrer un commentaire