您可以使用array_filter仅在数组中保留“真实”的值,如下所示:
array_filter($array);
如果您明确只希望non-
empty,或者您的过滤器功能更复杂:
array_filter($array, function($x) { return !empty($x); });# function(){} only works in in php >5.3, otherwise use create_function因此,仅计算非空项目,就像调用
empty(item)每个空项目一样:
count(array_filter($array, function($x) { return !empty($x); }));


