Oihana PHP Arango

unshift.php

Table of Contents

Functions

unshift()  : string
Prepend a value to the beginning of an array.

Functions

unshift()

Prepend a value to the beginning of an array.

unshift(mixed $anyArray, mixed $value[, bool $unique = false ]) : string

This helper wraps the ArangoDB AQL function UNSHIFT(anyArray, value, unique) which adds a value to the beginning of an array. If unique is true, the value is only added if it's not already present in the array.

Example AQL usage:

UNSHIFT([2, 4, 6], 1)           // returns [1, 2, 4, 6]
UNSHIFT([2, 4, 6], 4)           // returns [4, 2, 4, 6]
UNSHIFT([2, 4, 6], 4, true)     // returns [2, 4, 6] (4 already exists)
UNSHIFT([2, 4, 6], 1, true)     // returns [1, 2, 4, 6] (1 is new)
Parameters
$anyArray : mixed

Array expression to prepend value to.

$value : mixed

Value to prepend to the array.

$unique : bool = false

When true, value is added only if not already present.

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

$expr = unshift('[2,4,6,8]', 4);
// Produces: 'UNSHIFT([2,4,6,8], 4)'

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

For appending values to the end.

shift()

For removing elements from the beginning.

since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results