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('Create', 'Cre'),
    b: starts_with('Create', 'C'),
    c: starts_with('Create', 'c'),
    d: starts_with('Create', 'ate'),
    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.