3v4l.org

run code in 300+ PHP versions simultaneously
<?php DEFINE('FILTER_OPTIONS', ['odd', 'even']); /* Array filtering * * @param $array array the input array * @param $filterParameter string 'odd' or 'even' * * @return array|bool it returns the filtered array. In any other case it should return false. */ function filterArray($array, $filterParameter) { if (! is_array($array) || ! in_array($filterParameter, FILTER_OPTIONS)) { return false; } return array_filter($array, function ($e) use ($filterParameter) { return $filterParameter === 'odd' ? $e % 2 === 1 : $e % 2 === 0; }); } $array = [1,2,3,4,5,6,7]; var_dump(filterArray(1, 'odd'));

preferences:
47.57 ms | 402 KiB | 5 Q