Home  >  Article  >  Backend Development  >  Code sharing for cleverly using the array_filter() function in PHP to remove multi-dimensional null values_PHP Tutorial

Code sharing for cleverly using the array_filter() function in PHP to remove multi-dimensional null values_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:16:52944browse

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!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325822.htmlTechArticleIn fact, we can use the array_filter function to easily remove multi-dimensional null values ​​without changing the subscript of the array. Here is an example usage :?php $array = array( 0 = 'Brother Tao', 1 = false, 2 = 1, 3...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn