$ _ POST ['drinks'] is an array. In addition, the id value should not be "drinks []"
Try something like this:
$drinksIndex = 0;
$drinksPost = $_POST['drinks'];
foreach ($drinks_checkbox as $option => $options){ ?>
<input type='checkbox' id='drinks<?php echo $drinksIndex; ?>' name='drinks[<?php echo $drinksIndex; ?>]' value='<?php echo $option;?>'<?php
if( !empty($drinksPost[$drinksIndex]) ) echo " checked='checked'";
$drinksIndex++;
?> /><?php
echo $options;?><br />
<?php
} ?>
Part changed! empty ($ drinksPost [$ drinksIndex]) and changed to associative.
If this does not work, you can enable $ drinks_checkbox
source
share