PHP中的数组从复选框中选择多个

I have an array from checked checkboxes named with numbers which can be true or false i want to get only then numbers that are 1.
For example:

Array ( [8] => 1 [13] => 1 [14] =>  [15] => 1 [16] =>  )

i want an array with numbers 8,13,15 because they are 1 in previous array. Thanks for any help

Use array_filter

<?php
$result = array_filter($input, function($var){return $var==1;});

Just try with array_filter:

$input  = array(8 => 1, 13 => 1, 14 => null, 15 => 1, 16 => null);
$output = array_filter($input);

var_dump($output);

Output:

array (size=3)
  8 => int 1
  13 => int 1
  15 => int 1