This solution is inspired by @desw's one.
If your input names are in "form style", you will lose array index association with your chekbox values as soon as one chekbox is checked, incrementing this "dissociation" by one unit each time a chekbox is checked. This can be the case of a form for inserting something like employees composed by some fields, for instance:
<input type="text" name="employee[]" />
<input type="hidden" name="isSingle[] value="no" />
<input type="checkbox" name="isSingle[] value="yes" />
In case you insert three employees at once and the first and the second ones are single, you will end up with a 5-element isSingle
array, so you won't be able to iterate at once through the three arrays in order to, for instance, insert employees in a database.
You can overcome this with some easy array postprocessing. I'm using PHP at the server side and I did this:
$j = 0;
$areSingles = $_POST['isSingle'];
foreach($areSingles as $isSingle){
if($isSingle=='yes'){
unset($areSingles[$j-1]);
}
$j++;
}
$areSingles = array_values($areSingles);