PHP Santizing/Validating Array of Integers
Since it's $_POST
data, you'll want to check for ctype_digit
(i.e. a string containing only digits):
$sanitizedValues = array_filter($_POST['taxonomy'], 'ctype_digit');
Note that this simply discards non-numeric values.
An alternative would be using phps filter functions:
$array = array( 13, 12, '1', 'a');$result = filter_var($array, FILTER_VALIDATE_INT, array( 'flags' => FILTER_REQUIRE_ARRAY, 'options' => array('min_range' => 1)));var_dump($result);/*array(4) { [0]=> int(13) [1]=> int(12) [2]=> int(1) [3]=> bool(false)}*/
if(is_array($_POST['taxonomy'])) { $term_ids = array_map('intval', $_POST['taxonomy']);}
Should do the trick. NOTE: this is sanitation. More: http://php.net/manual/en/function.intval.php