Oihana PHP Arango

matches.php

Table of Contents

Functions

matches()  : string
Test whether a document matches one of the given example documents.

Functions

matches()

Test whether a document matches one of the given example documents.

matches(string $document, string|array<string|int, mixed> $examples[, bool|null $returnIndex = null ]) : string

Wraps the ArangoDB AQL function MATCHES(document, examples, returnIndex). The examples argument is emitted as a JSON literal when given as a PHP array; a string is passed through as a raw AQL expression. With $returnIndex = true, the function returns the (zero-based) index of the first matching example instead of a boolean.

Example AQL usage:

MATCHES(doc, {age: 30})                       // true if doc.age == 30
MATCHES(doc, [{age: 30}, {age: 40}], true)    // index of the first matching example, or -1
Parameters
$document : string

The document variable or expression to test.

$examples : string|array<string|int, mixed>

A single example or a list of examples (array literal or AQL expression).

$returnIndex : bool|null = null

Whether to return the matching example index instead of a boolean.

Tags
example
use function oihana\arango\db\functions\documents\matches;

$expr = matches('doc', ['age' => 30]);
// Produces: 'MATCHES(doc,{"age":30})'

$expr = matches('doc', [['age' => 30], ['age' => 40]], true);
// Produces: 'MATCHES(doc,[{"age":30},{"age":40}],true)'
see
https://docs.arangodb.com/stable/aql/functions/document-object/#matches
since
1.1.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results