Oihana PHP Arango

position.php

Table of Contents

Functions

position()  : string
Returns the position of a value in an array.

Functions

position()

Returns the position of a value in an array.

position(mixed $anyArray, int|string $search[, bool $returnIndex = false ]) : string

This helper wraps the ArangoDB AQL function POSITION(anyArray, search, returnIndex) which searches for a value in an array and returns either its position or a boolean indicating whether the value was found.

Example AQL usage:

POSITION([2, 4, 6, 8], 4)           // returns 1 (position of 4)
POSITION([2, 4, 6, 8], 4, true)     // returns 1 (same as above)
POSITION([2, 4, 6, 8], 5, false)    // returns false (not found)
POSITION([2, 4, 6, 8], 5)           // returns false (default behavior)
Parameters
$anyArray : mixed

Array expression to search in.

$search : int|string

Value to search for in the array.

$returnIndex : bool = false

When true, returns the index position; when false, returns boolean.

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

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

$expr = position('[2,4,6,8]', 4, true);
// Produces: 'POSITION([2,4,6,8],4,true)'
see
https://docs.arangodb.com/stable/aql/functions/array/#position
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results