remove empty value from 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: 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 3: php remove empty values from array
$array = array_filter($array, function($a) {return $a !== "";});
$array = array_filter($array, function($a) {
return trim($a) !== "";
});
Example 4: remove empty array elements php
$colors = array("red","","blue",NULL);
$colorsNoEmptyOrNull = array_filter($colors, function($v){
return !is_null($v) && $v !== '';
});
Example 5: remove null values from array php
array_filter
Example 6: how to remove NULL values in array PHP
array_filter();