This article mainly introduces the implementation code of using the array_filter () function to filter empty arrays in php. this is an interesting array_filter () function usage that is not intended to be found in the PHP Manual, for more information about how to use array_filter (), see the following key points: If no callback is supplied, all entries of input equal to FALSE (see converting to boolean) will be removed. if no callback function is provided, all the elements equal to FALSE will be removed. can this function be used to filter arrays with empty elements? Write an example to test the idea:
The code is as follows:
$ Entry = array (
0 => 'blog of Blue Hawaiian ',
1 => false,
2 => 1,
3 => null,
4 => '',
5 => 'http: // www.jb51.net ',
6 => '0 ',
7 => array (),
8 => 0
);
$ Validarr = array_filter ($ entry );
Print_r ($ validarr );
// Output result:
Array
(
[0] => Blue Hawaiian blog
[2] => 1
Http://www.jb51.net
)
Some array elements that can be converted to Boolean FALSE are removed, and we want to get a valid array for a very comprehensive filter.