Oihana PHP Arango

aqlSort.php

Table of Contents

Functions

aqlSort()  : string
Builds an AQL `SORT` clause from a string or an array of sort expressions.

Functions

aqlSort()

Builds an AQL `SORT` clause from a string or an array of sort expressions.

aqlSort(string|array<string|int, mixed>|null $expression) : string

This helper assembles a valid SORT operation for AQL queries. It accepts a single sort expression or multiple ones (as an array), and automatically joins them with commas when needed.

Each expression can be generated manually or using helpers like aqlAsc() and aqlDesc().

Example: with a single key

echo aqlSort('user.age ASC');
// → "SORT user.age ASC"

Example: with multiple expressions

echo aqlSort([
    aqlAsc('score', 'player'),
    aqlDesc('createdAt', 'doc')
]);
// → "SORT player.score ASC, doc.createdAt DESC"

Example: empty or null input

echo aqlSort(null);     // → ""
echo aqlSort([]);       // → ""
echo aqlSort('');       // → ""
Parameters
$expression : string|array<string|int, mixed>|null

The sort expression(s). Can be:

  • a string ("age ASC")
  • an array of expressions (["a ASC", "b DESC"])
  • null or empty string for no output
Tags
see
aqlAsc()

For ascending order helpers.

aqlDesc()

For descending order helpers.

https://docs.arangodb.com/stable/aql/fundamentals/sorting
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted SORT clause, or an empty string if no expression is provided.

On this page

Search results