Home  >  Article  >  Backend Development  >  PHP去除数组里的空值的方法

PHP去除数组里的空值的方法

WBOY
WBOYOriginal
2016-06-20 13:01:311753browse

PHP去除数组里面的空值,我们可以用PHP自带函数array_filter();

也可以利用

array_diff()函数

array_diff — 计算数组的差集

说明

array

array_diff

( array $array1, array $array2 [, array $ ...] )

array_diff() 返回一个数组,该数组包括了所有在 array1 中但是不在任何其它参数数组中的值。注意键名保留不变。

去空值的例子:

$array = array("a","b","",null,"c");

$array = array_diff($array, array(null));

即可去除.


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