php remove blank values from array code example
Example 1: php remove blank values from array
print_r(array_filter($linksArray, fn($value) => !is_null($value) && $value !== ''));
print_r(array_filter($linksArray, function($value) { return !is_null($value) && $value !== ''; }));
print_r(array_filter($linksArray, create_function('$value', 'return $value !== "";')));
Example 2: php remove empty values from array
$array = array_filter($array, function($a) {return $a !== "";});
$array = array_filter($array, function($a) {
return trim($a) !== "";
});
Example 3: remove empty array elements php
$colors = array("red","","blue",NULL);
$colorsNoEmptyOrNull = array_filter($colors, function($v){
return !is_null($v) && $v !== '';
});