I am writing a drupal module that involves a form with many checkboxes. E.g.
$form['myform_checkboxes'] = array('#type' => 'checkboxes', ...)
I have made the key for these checkboxes numeric, starting with 0. E.g.
$form['myform_checkboxes']['#options'][0] = '0:00';
$form['myform_checkboxes']['#options'][1] = '1:00';
Upon implementing the myform_checkboxes_submit function, I have discovered that it is difficult to interpret what the user's input was. On the interwebs, I found a few nice lines of code that did what I needed.
$checked = array_intersect(
array_keys($form_state['values']['myform_checkboxes']),
array_values($form_state['values']['myform_checkboxes'])
);
This seems to work great; the $checked variable is an array including only the checked checkboxes. The only problem is that the value 0 (representing the 0th checkbox) is always included in $checked, whether it was actually checked or not.
Also useful to note: the zero appears first in the list if it is was checked, but last if it is not.
What would be the best way to resolve this situation, assuming that changing the indexing of the checkboxes were out of the question? (Related bonus question: is there an easier way to get the user's checked boxes from the drupal form variables?)