Oihana PHP Arango

toNumber.php

Table of Contents

Functions

toNumber()  : string
Converts a value of any type into a numeric value.

Functions

toNumber()

Converts a value of any type into a numeric value.

toNumber(mixed $value) : string

This helper wraps the ArangoDB AQL function TO_NUMBER(), which casts the provided value to a number. Conversion rules follow AQL semantics:

  • Strings containing numeric representations are converted to numbers.
  • Boolean true becomes 1, false becomes 0.
  • null is converted to 0.

Example AQL usage:

TO_NUMBER("42")       // returns 42
TO_NUMBER(doc.count)  // converts the doc.count field to a number
TO_NUMBER(true)       // returns 1
TO_NUMBER(null)       // returns 0
Parameters
$value : mixed

The AQL field or expression to convert to a number.

Tags
example
use function oihana\arango\db\functions\toNumber;

$expr = toNumber('doc.age');
// Produces: 'TO_NUMBER(doc.age)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#to_number
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g., 'TO_NUMBER(doc.age)').

On this page

Search results