Oihana PHP Arango

arrayContains.php

Table of Contents

Functions

arrayContains()  : string
Build an AQL array "question mark" inline filter `array[? <quantifier> FILTER <condition>]`.

Functions

arrayContains()

Build an AQL array "question mark" inline filter `array[? <quantifier> FILTER <condition>]`.

arrayContains(string $array, string $condition[, string $quantifier = Char::EMPTY ]) : string

Unlike arrayFilter() ([* FILTER cond], which returns the matching sub-array), the question-mark operator returns a boolean: whether the array contains elements satisfying $condition under the given quantifier. It is the direct, idiomatic way to write the existential LENGTH(array[* FILTER cond]) > 0 and, with a quantifier, the ALL / NONE / AT LEAST (n) variants.

Supported quantifiers (omitted = "at least one"):

  • '' → at least one element matches (default);
  • ANY / ALL / NONE;
  • AT LEAST (n) → at least n elements match.

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

Parameters
$array : string

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

$condition : string

The FILTER condition tested on each element.

$quantifier : string = Char::EMPTY

An optional quantifier (ANY, ALL, NONE, AT LEAST (n)); empty = at least one.

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

echo arrayContains( 'doc.contactPoint' , 'CURRENT.email != null' );
// doc.contactPoint[? FILTER CURRENT.email != null]

echo arrayContains( 'doc.reviews' , 'CURRENT.rating >= @v' , 'AT LEAST (3)' );
// doc.reviews[? AT LEAST (3) FILTER CURRENT.rating >= @v]

echo arrayContains( 'doc.flags' , 'CURRENT == true' , 'NONE' );
// doc.flags[? NONE FILTER CURRENT == true]
see
arrayFilter()

For the sub-array form [* FILTER cond].

https://docs.arangodb.com/stable/aql/operators/#question-mark-operator
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL boolean array-contains expression.

On this page

Search results