30 seconds of PHP

  Back to Home

all

arraybeginner

Returns true if the provided function returns true for all elements of an array, false otherwise.

Use array_filter() and count() to check if $func returns true for all the elements in $items.

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