php利用array_filter()过滤数组空值
利用array_filter过滤数组空值
<?php
$array = array(
0 => '霜天部落',
1 => false,
2 => 1,
3 => null,
4 => '',
5 => 'http://www.hzhuti.com',
6 => '0'
);
$rs = array_filter($array);
print_r($rs);
/*
输出结果为:
Array
(
[0] => 霜天部落
[2] => 1
[5] => http://www.hzhuti.com
)
*/
//计算数组不为空元素个数的方法
$cou = count(array_filter($array));
print_r($cou);
//输出结果:3