1. Home
  2. Computer Science MCQs
  3. PHP
  4. Which function, added in PHP 8.0, checks whether a string…

Added 2 Nov 2026

Which function, added in PHP 8.0, checks whether a string contains a given substring?

  1. str_contains() Correct answer
  2. str_has()
  3. in_string()
  4. contains()

Correct answer

A. str_contains()

17 views

MCQSEXAM

Explanation

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().

Reference

Asked in: NTS, PHP Developer Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More PHP MCQs

Practise all PHP MCQs

Similar MCQs