How to get checkboxes values in a form? This is my code :

$form['how_many'] = [
  '#type' =&gt; 'checkboxes',
  '#required' =&gt; true,
  '#options' =&gt; [
     '1' =&gt; t('one'),
     '2' =&gt; t('two'),
     '3' =&gt; t('three')
  ],
  '#title' =&gt; t('How many')
];


I want to get the checkbox values.

When I do $form_state-&gt;getValue('how_many');, I get an array with filed value as well as non-filled as 0. 

If i do $form_state-&gt;getValue('how_many[1]');, I get nothing and if I do $form_state-&gt;getCheckedCheckboxes('how many'), the page shows nothing.
May be you can try this:

$result = $form_state-&gt;getValue('how_many');
$value = array_filter($result);

//print to check the value 

print_r($value);