Oihana PHP Arango

slice.php

Table of Contents

Functions

slice()  : string
Extract a slice from an array.

Functions

slice()

Extract a slice from an array.

slice(mixed $anyArray, int $start, int|null $length) : string

This helper wraps the ArangoDB AQL function SLICE(anyArray, start, length) which extracts a portion of an array starting from the specified index. The length parameter is optional - if not provided, all elements from the start position to the end are included.

Example AQL usage:

SLICE([1, 2, 3, 4, 5], 1, 2)       // returns [2, 3]
SLICE([1, 2, 3, 4, 5], 2)          // returns [3, 4, 5]
SLICE([1, 2, 3, 4, 5], 0, 3)       // returns [1, 2, 3]
Parameters
$anyArray : mixed

Array expression to slice.

$start : int

Starting index (zero-based) for the slice.

$length : int|null

Optional length of the slice (null = to end of array).

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

$expr = slice('[1, 2, 3]', 0, 1);
// Produces: 'SLICE([1, 2, 3],0,1)'

$expr = slice('doc.items', 5);
// Produces: 'SLICE(doc.items,5)'
see
https://docs.arangodb.com/stable/aql/functions/array/#slice
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results