Oihana PHP Arango

translate.php

Table of Contents

Functions

translate()  : string
Look up the specified value in a lookup document and return the mapped value.

Functions

translate()

Look up the specified value in a lookup document and return the mapped value.

translate(mixed $value, mixed $lookupDocument[, mixed $defaultValue = null ]) : string

This helper wraps the ArangoDB AQL function TRANSLATE(value, lookupDocument, defaultValue) which performs a lookup operation. If the value is a key in the lookup document, it returns the corresponding value. If not found, it returns the default value (if specified) or the original value unchanged.

Example AQL usage:

TRANSLATE("draft", {"draft": "D", "published": "P"})           // returns "D"
TRANSLATE("unknown", {"draft": "D", "published": "P"})         // returns "unknown"
TRANSLATE("unknown", {"draft": "D", "published": "P"}, "X")    // returns "X"
Parameters
$value : mixed

The value to look up in the lookup document.

$lookupDocument : mixed

The document containing key-value mappings.

$defaultValue : mixed = null

Optional default value to return if key is not found.

Tags
example
use function oihana\arango\db\functions\documents\translate;

$expr = translate('status', '{"draft": "D", "published": "P"}', 'unknown');
// Produces: 'TRANSLATE("status", {"draft": "D", "published": "P"}, "unknown")'
see
https://docs.arangodb.com/stable/aql/functions/document-object/#translate
since
1.0.0
author

Marc Alcaraz

Return values
string

The formatted AQL expression.

On this page

Search results