Oihana PHP Arango

flatten.php

Table of Contents

Functions

flatten()  : string
Turn an array of arrays into a flat array, down to a given depth.

Functions

flatten()

Turn an array of arrays into a flat array, down to a given depth.

flatten(mixed $anyArray[, int|null $depth = null ]) : string

This helper wraps the ArangoDB AQL function FLATTEN(anyArray, depth). Without a depth, one level is flattened.

Example AQL usage:

FLATTEN([ 1 , [ 2 , 3 ] , [ 4 , [ 5 ] ] ])     // [ 1 , 2 , 3 , 4 , [ 5 ] ]
FLATTEN([ 1 , [ 2 , 3 ] , [ 4 , [ 5 ] ] ] , 2) // [ 1 , 2 , 3 , 4 , 5 ]
FLATTEN(doc.stops[*].scans)                    // every scan of every stop
Parameters
$anyArray : mixed

The array expression to flatten.

$depth : int|null = null

How many levels to flatten, one when null.

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

flatten( 'doc.stops[*].scans' ) ;     // 'FLATTEN(doc.stops[*].scans)'
flatten( 'doc.a[*].b[*].c' , 2 ) ;    // 'FLATTEN(doc.a[*].b[*].c,2)'
see
https://docs.arangodb.com/stable/aql/functions/array/#flatten
author

Marc Alcaraz

Return values
string —

The formatted AQL expression.

On this page

Search results