ends_with

Check if a string ends with a given suffix

Definition

boolean ends_with(string $subject, string $suffix)

Checks if $subject ends with $suffix.

Parameters

string $subject

The string to check the ending of.

string $suffix

The suffix for which the string is checked.

Returns

boolean

true if $subject ends with $suffix, otherwise false.

Examples

{
    a: ends_with('Hello, world', 'world'),
    b: ends_with('Hello, world', 'hello'),
    c: ends_with('Hello, world', 'd'),
    d: ends_with('Hello, world', ''),
    e: ends_with('Hello, world', `null`)      // Error
}
{
  "a": true,
  "b": false,
  "c": true,
  "d": true
}