Oihana PHP Arango

startsWith.php

Table of Contents

Functions

startsWith()  : string
Check whether a string starts with a prefix (or with one of several prefixes).

Functions

startsWith()

Check whether a string starts with a prefix (or with one of several prefixes).

startsWith(string $value, string|array<string|int, mixed> $prefix[, int|null $minMatchCount = null ]) : string

This helper wraps the ArangoDB AQL function STARTS_WITH(text, prefix) which checks if the given string starts with the specified prefix. The comparison is case-sensitive.

Inside a SEARCH operation the ArangoSearch form STARTS_WITH(path, prefixes, minMatchCount) is also supported: pass an array of prefixes (emitted with json_encode, so plain strings are quoted) and an optional minimum number of prefixes that must match. A string prefix is kept raw, as before (callers quote it themselves).

Example AQL usage:

STARTS_WITH("hello world", "hello")       // returns true
STARTS_WITH("hello world", "world")       // returns false
STARTS_WITH("Hello world", "hello")       // returns false (case-sensitive)
STARTS_WITH(doc.text, ["lor", "ips"], 1)  // SEARCH form: at least 1 prefix matches
Parameters
$value : string

String expression to check.

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

Prefix to test for: a raw string expression (kept as-is), or an array of prefix strings (JSON-encoded).

$minMatchCount : int|null = null

Optional minimum number of prefixes that must match (ArangoSearch SEARCH form, used with an array of prefixes).

Tags
example
use function oihana\arango\db\functions\strings\startsWith;

$expr = startsWith('doc.name', '"John"');
// Produces: 'STARTS_WITH(doc.name,"John")'

$expr = startsWith('doc.text', [ 'lor' , 'ips' ] , 1 );
// Produces: 'STARTS_WITH(doc.text,["lor","ips"],1)'
see
https://docs.arangodb.com/stable/aql/functions/string/#starts_with
https://docs.arangodb.com/stable/aql/functions/arangosearch/#starts_with
contains()

For checking if string contains substring.

like()

For pattern matching.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results