Oihana PHP Arango

sortKeys.php

Table of Contents

Functions

sortKeys()  : string
Composes a comma-separated sort expression in the textual sort grammar (the same grammar consumed by `SortTrait::prepareSort` and the HTTP `?sort=` query parameter).

Functions

sortKeys()

Composes a comma-separated sort expression in the textual sort grammar (the same grammar consumed by `SortTrait::prepareSort` and the HTTP `?sort=` query parameter).

sortKeys(string ...$keys) : string

Each argument is a sort token, typically produced by ascKey() or descKey() but plain field constants are accepted as well (an unprefixed key implies ascending order).

Null and empty tokens are skipped via compile(), so callers can pass conditional tokens without array_filter() boilerplate.

Parameters
$keys : string

One or more sort tokens (e.g. 'name', '-created').

Tags
example
use App\Enums\Prop;
use oihana\arango\enums\Arango;

use function oihana\arango\helpers\descKey;
use function oihana\arango\helpers\sortKeys;

sortKeys( descKey( Prop::CREATED ) )                                    ; // '-created'
sortKeys( descKey( Prop::CREATED ) , Prop::NAME )                       ; // '-created,name'
sortKeys( descKey( Prop::CREATED ) , descKey( Prop::NAME ) )            ; // '-created,-name'
sortKeys()                                                              ; // ''

Arango::SORT => sortKeys( descKey( Prop::CREATED ) , Prop::_KEY ) ;
see
ascKey()

Ascending sort token.

descKey()

Descending sort token.

author

Marc Alcaraz

Return values
string

The comma-joined sort expression, or an empty string when no tokens are given.

On this page

Search results