starts_with
Check if a function starts with a given prefix
Definition
boolean starts_with(string $text, string $prefix)
Checks if $text
starts with $prefix
. Case-sensitive.
Parameters
string $text
The string to check the start of.
string $suffix
The prefix for which the string is checked.
Returns
boolean
true
if $text
starts with $prefix
, otherwise false
.
Examples
{
a: starts_with('Documotor', 'Doc'),
b: starts_with('Documotor', 'D'),
c: starts_with('Documotor', 'd'),
d: starts_with('Documotor', 'motor'),
e: starts_with(`123`, `1`),
f: starts_with(`123`, `2`),
g: starts_with(`{"a": 1}`, `"a"`)
}
{
"a": true,
"b": true,
"c": false,
"d": false,
"e": true,
"f": false,
}
Remarks
Designed for strings, but works for numbers as well.
Updated 7 months ago