30 seconds of PHP

  Back to Home

any

arraybeginner

Returns true if the provided function returns true for at least one element of an array, false otherwise.

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

function any($items, $func)
{
  return count(array_filter($items, $func)) > 0;
}