Pike v8.1 release 6

Method Array.count()


Method count

int count(array|mapping|multiset haystack, mixed needle)
mapping(mixed:int) count(array|mapping|multiset haystack)

Description

Returns the number of occurrences of needle in haystack. If the optional needle argument is omitted, count instead works similar to the unix command sort|uniq -c, returning a mapping with the number of occurrences of each element in haystack. For array or mapping haystacks, it's the values that are counted, for multisets the indices, as you'd expect.

See also

String.count, search, has_value