form #type => checkboxes with zero / empty option value
I managed to prevent this problem by adding an '#element_validate' handler on the checkboxes element.

The code below is a simplified version of what I did, up to you to fine-tune.

$element['#element_validate'][] = '_MYMODULE_checkboxes_validate';

function _MYMODULE_checkboxes_validate(array &amp;$element, array &amp;$form_state) {

  // The form value already has the format $[$id] = $id, mostly.
  // However, if trim($id) === '', the array key will be an integer increment.
  $value = $element['#value'];

  // Make sure it has the expected format.
  if (!is_array($value) || [] === $value) {
    $ids = [];
  }
  else {
    // Get rid of integer keys for empty-ish string ids.
    $ids = array_combine($value, $value);
  }

  // Remove dangling * =&gt; 0 entries.
  form_set_value($element, $ids, $form_state);
}


Note: If you have the value_is module installed, empty-ish values will always be unset, thanks to _value_is_disabled_options_value_callback().