Which function, added in PHP 8.0, checks whether a string contains a given substring?
Correct answer
A. str_contains()
17 views
A. str_contains()
17 views
str_contains($haystack, $needle) returns true or false. It replaces the error-prone strpos() !== false idiom. PHP 8 also added str_starts_with() and str_ends_with().
Asked in: NTS, PHP Developer Interviews
Not sure why the answer is A? Ask here and get an explanation.