$my_array = array(2, "a", null, 2.5, NULL, 0, "", 8, -1,array()); class ArrayFilter { public static function not_empty($v) { if($v !== null && trim($v) !== '' && $v !== array()) { return true; } } function filter($values) { return array_filter($values, "self::not_empty"); } } $arrayFilter = new ArrayFilter(); print_r($arrayFilter->filter($my_array));Result:
C:\>php -f filter.php Array ( [0] => 2 [1] => a [3] => 2.5 [5] => 0 [7] => 8 [8] => -1 ) C:\>
No comments:
Post a Comment