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

WBOY
Release: 2016-06-20 13:01:31
Original
1673 people have browsed it

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));

即可去除.


Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!