1<?php
2$arr = array('1', '', '2', '3', '0');
3// Incorrect:
4print_r(array_filter($arr));
5// Correct:
6print_r(array_filter($arr, 'strlen'));
7//Custom
8print_r(array_filter($arr, function ($val) {if ($val > 0) {return true;} else {return false;}}));
1$colors = array("red","","blue",NULL);
2
3$colorsNoEmptyOrNull = array_filter($colors, function($v){
4 return !is_null($v) && $v !== '';
5});
6//$colorsNoEmptyOrNull is now ["red","blue"]