In case you are using an older version of PHP (e.g. PHP 7), you can define and use the following function:
function endsWith($haystack, $needle) {
$length = strlen($needle);
return $length > 0 ? substr($haystack, -$length) === $needle : true;
}