added helper function: endsWith($haystack, $needle)