Oihana PHP Arango

toBool.php

Table of Contents

Functions

toBool()  : string
Converts a value of any type into a boolean.

Functions

toBool()

Converts a value of any type into a boolean.

toBool(mixed $value) : string

This helper wraps the ArangoDB AQL function TO_BOOL(), which casts the provided value to a boolean. The conversion rules follow AQL semantics:

  • Non-zero numbers and non-empty strings evaluate to true.
  • Zero, empty strings, null, and empty arrays evaluate to false.

Example AQL usage:

TO_BOOL(doc.isActive)   // converts doc.isActive to boolean
TO_BOOL("")             // returns false
TO_BOOL(1)              // returns true
Parameters
$value : mixed

The AQL field or expression to convert to boolean.

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

$expr = toBool('doc.isActive');
// Produces: 'TO_BOOL(doc.isActive)'
see
https://docs.arangodb.com/stable/aql/functions/type-check-and-cast/#to_bool
since
1.0.0

author Marc Alcaraz

Return values
string

The formatted AQL expression (e.g., 'TO_BOOL(doc.isActive)').

On this page

Search results