Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 613 Bytes

all.md

File metadata and controls

23 lines (17 loc) · 613 Bytes
标题 标签
all(检查数组所有元素) array,beginner(数组,初学者)

如果提供的函数对数组的所有元素返回 true,则返回 true,否则返回 false。

  • 使用 array_filter()count() 检查 $func 是否对 $array 中的所有元素返回 true。

代码如下:

function all($array,$func){
    return count(array_filter($array,$func)) === count($array);
}

使用方式:

all([2, 3, 4, 5], function ($item) {
  return $item > 1;
}); // true