【发布时间】:2018-04-23 12:10:34
【问题描述】:
我有一个数组 $captions,我想检查里面是否至少有一个值。数组可能如下所示:
Array
(
[0] => 84
[1] =>
[2] => 82
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
以及我检查是否有“超过0”,“超过1”的方法......
if (count($captions) > 0) { echo '<br>bigger than 0';}
if (count($captions) === 1) {echo '<br>is 1';};
if (count($captions) > 1) {echo '<br>gbigger than 1';};
if (count($captions) > 2) {echo '<br>bigger than 2';}
但是:它给了我这个数组上面的结果:
bigger than 0
bigger than 1
bigger than 2
“大于2”不应该,因为数组只包含两个值?我哪里错了?
【问题讨论】:
-
使用array_filter()
-
它是计数数组的空值,所以使用 array_filter($array)