removes empty values in array php code example
Example 1: php array remove empty values
<?php
$arr = array('1', '', '2', '3', '0');
print_r(array_filter($arr));
print_r(array_filter($arr, 'strlen'));
print_r(array_filter($arr, function ($val) {if ($val > 0) {return true;} else {return false;}}));
Example 2: remove empty array elements php
$colors = array("red","","blue",NULL);
$colorsNoEmptyOrNull = array_filter($colors, function($v){
return !is_null($v) && $v !== '';
});
Example 3: remove null values from array php
array_filter