Oihana PHP Arango

nth.php

Table of Contents

Functions

nth()  : string
Get the element at the given position in an array.

Functions

nth()

Get the element at the given position in an array.

nth(mixed $anyArray, int $position) : string

This helper wraps the ArangoDB AQL function NTH(anyArray, position) which returns the element at the specified zero-based position in the array. If the position is out of bounds, it returns null.

Note: Negative positions are not supported in ArangoDB AQL.

Example AQL usage:

NTH([2, 4, 6, 8], 0)        // returns 2 (first element)
NTH([2, 4, 6, 8], 2)        // returns 6 (third element)
NTH([2, 4, 6, 8], 10)       // returns null (out of bounds)
Parameters
$anyArray : mixed

Array expression to get element from.

$position : int

Zero-based position of the element to retrieve.

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

$expr = nth('[2,4,6,8]', 2);
// Produces: 'NTH([2,4,6,8],2)'
see
https://docs.arangodb.com/stable/aql/functions/array/#nth
first()

For getting the first element.

last()

For getting the last element.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results