split.php
Table of Contents
Functions
- split() : string
- Split a string into an array using a separator.
Functions
split()
Split a string into an array using a separator.
split(string $value, string $separator[, int|null $limit = null ]) : string
This helper wraps the ArangoDB AQL function SPLIT(value, separator, limit)
which splits the given string into an array of strings using the specified
separator. The limit is optional, and omitting it splits the whole value.
Example AQL usage:
SPLIT("a,b,c", ",") // returns ["a", "b", "c"]
SPLIT("hello world", " ") // returns ["hello", "world"]
SPLIT("hello", "") // returns ["h", "e", "l", "l", "o"] (split by character)
⚠ The limit truncates, it does not merge. AQL keeps the first limit
parts and discards the rest, where PHP's own explode() merges the
remainder into the last element. The two read alike and answer differently:
SPLIT("a,b,c,d", ",", 3) // returns ["a", "b", "c"] — "d" is gone
SPLIT("a,b,c,d", ",", 1) // returns ["a"]
SPLIT("a,b,c,d", ",", 0) // returns [] — keep nothing
explode(",", "a,b,c,d", 3); // returns ["a", "b", "c,d"] — "d" is kept
explode(",", "a,b,c,d", 0); // returns ["a,b,c,d"] — 0 is read as 1
A limit of 0 is therefore an empty answer in AQL and a whole one in PHP.
Pass null — not 0 — to mean "no limit".
Parameters
- $value : string
-
String expression to split.
- $separator : string
-
Separator string to split on, quoted by the caller when it is text.
- $limit : int|null = null
-
Optional number of parts to keep.
nullomits the argument and splits the whole value.
Tags
Return values
string —The formatted AQL expression.