Oihana PHP Arango

sortedUnique.php

Table of Contents

Functions

sortedUnique()  : string
Sort the elements of an array and remove duplicates.

Functions

sortedUnique()

Sort the elements of an array and remove duplicates.

sortedUnique(mixed $anyArray) : string

This helper wraps the ArangoDB AQL function SORTED_UNIQUE(anyArray) which returns a new array with all elements sorted in ascending order and duplicates removed. The original array is not modified.

Example AQL usage:

SORTED_UNIQUE([8, 4, 2, 10, 6, 2, 8, 6, 4])    // returns [2, 4, 6, 8, 10]
SORTED_UNIQUE(["c", "a", "b", "a", "c"])        // returns ["a", "b", "c"]
SORTED_UNIQUE(doc.tags)                         // sorts and deduplicates tags
Parameters
$anyArray : mixed

Array expression to sort and deduplicate.

Tags
example
use function oihana\arango\db\functions\arrays\sortedUnique;

$expr = sortedUnique('[8,4,2,10,6,2,8,6,4]');
// Produces: 'SORTED_UNIQUE([8,4,2,10,6,2,8,6,4])'
see
https://docs.arangodb.com/stable/aql/functions/array/#sorted_unique
sorted()

For sorting without removing duplicates.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results