I am doing this check in a <select>
field and everything is working fine but I would like to do the same check in a <checkbox>
that can have several possibilities, then need to work with arrays
so I do not know how to proceed.
Below the code I use for <select>
:
PHP
if( isset( $_POST['valorminimo'] ) ) $_SESSION['valorminimo'] = $_POST['valorminimo'];
HTML
<option value="1mil" <?php echo (($valormaximo == '1mil') ? 'selected="selected"' : ""); ?>>1mil</option>
Now I have the code PHP
below for the checkboxes
that retrieves the indexes correctly and I need to know in HTML
how to do a ternary check to apply an effect on checked
.
PHP
$dorms = isset( $_SESSION['dorms'] ) ? $_SESSION['dorms'] : array();
HTML
<input id="dorm1" class="hidden drm" type="checkbox" name="dorms[]" value="1" <?php ((in_array($dorms)) ? "checked='checked'" : "" ); ?>>
<input id="dorm2" class="hidden drm" type="checkbox" name="dorms[]" value="2">
<input id="dorm3" class="hidden drm" type="checkbox" name="dorms[]" value="3+">
In short, how to check in every
input type checkbox
whether it ischecked
or not?