Home>Article>Backend Development> Code sharing for cleverly using the array_filter() function in PHP to remove multi-dimensional null values_PHP Tutorial
In fact, we can use the array_filter function to easily remove multi-dimensional null values without changing the subscript of the array. The following is an example of usage:
$array = array(
0 => 'Brother Tao ',
1 => false,
2 => 1,
3 => null,
4 => '',
5 => 'http:/ /www.jb51.net',
6 => '0'
);
print_r(array_filter($array));
?>
The output of the above code is:
Array
(
[0] => Brother Tao
[2] => 1
[5] => http://www.jb51.net
)
In this way, values that are empty, null, or false are excluded to avoid loopholes in the program!