Oihana PHP Arango

arrayFilter.php

Table of Contents

Functions

arrayFilter()  : string
Build an AQL array inline filter `array[* FILTER <condition>]`.

Functions

arrayFilter()

Build an AQL array inline filter `array[* FILTER <condition>]`.

arrayFilter(string $array, string $condition) : string

This is AQL's array expansion in its filtering form: it keeps the elements of $array for which $condition (which typically references the loop variable Clause::CURRENT) holds, yielding a sub-array. It is the filtering sibling of arrayMap() ([* RETURN expr]).

Combined with length() it expresses an existential test — LENGTH(doc.items[* FILTER CURRENT.active]) > 0 — though the boolean array "question mark" operator ([? FILTER …], see arrayContains()) is a more direct way to write the same intent.

$condition is interpolated verbatim — callers are responsible for building it from trusted/whitelisted pieces (bound values, validated fields, …).

Parameters
$array : string

The array expression to expand (e.g. doc.contactPoint).

$condition : string

The FILTER condition tested on each element (e.g. CURRENT.email != null).

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

echo arrayFilter( 'doc.contactPoint' , 'CURRENT.email != null' );
// doc.contactPoint[* FILTER CURRENT.email != null]
see
arrayMap()

For the projecting form [* RETURN expr].

https://docs.arangodb.com/stable/aql/operators/#array-expansion
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL inline filter.

On this page

Search results