Oihana PHP Arango

countDistinct.php

Table of Contents

Functions

countDistinct()  : string
Count the number of distinct elements in an array.

Functions

countDistinct()

Count the number of distinct elements in an array.

countDistinct(mixed $anyArray) : string

This helper wraps the ArangoDB AQL function COUNT_DISTINCT(anyArray) which returns the number of unique elements in the given array, removing duplicates before counting.

Example AQL usage:

COUNT_DISTINCT([1, 2, 3, 2, 1])     // returns 3 (unique elements: 1, 2, 3)
COUNT_DISTINCT(doc.tags)            // returns number of unique tags
Parameters
$anyArray : mixed

Array expression to count distinct elements of.

Tags
example
use function oihana\arango\db\helpers\arrays\countDistinct;

$expr = countDistinct('[1,2,3,2]');
// Produces: 'COUNT_DISTINCT([1,2,3,2])'
see
https://docs.arangodb.com/stable/aql/functions/array/#count_distinct
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results