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"
TRANSLATE("unknown", {"draft": "D", "published": "P"}, null) // returns null
Every argument is AQL text, written verbatim — nothing is quoted or encoded here.
A literal string must be quoted first (aqlValue( 'unknown' ) → 'unknown').
The default value : a PHP null (or an empty string) OMITS the third argument, and
TRANSLATE() then returns the value itself when it is not in the lookup. To return
the AQL null instead, pass AQL::NULL (the text null).
Parameters
- $value : mixed
-
The value to look up in the lookup document (AQL text).
- $lookupDocument : mixed
-
The document containing key-value mappings (AQL text).
- $defaultValue : mixed = null
-
Optional default value (AQL text) returned if the key is not found ;
nullomits it,AQL::NULLwrites the AQLnull.
Tags
Return values
string —The formatted AQL expression.