PHP - String FunctionsWhich of the following is the correct syntax to compare the first 4 characters of two strings case-insensitively in PHP?Astrncmp($str1, $str2, 4);Bstrncasecmp($str1, $str2, 4);Csubstr_compare($str1, $str2, 0, 4);Dstrcasecmp($str1, $str2);Check Answer
Step-by-Step SolutionSolution:Step 1: Understand function parametersstrncasecmp() compares first n characters ignoring case; here n=4.Step 2: Check other optionsstrncmp() is case-sensitive, substr_compare() is case-sensitive by default, strcasecmp() compares full strings.Final Answer:strncasecmp($str1, $str2, 4); -> Option BQuick Check:Case-insensitive first 4 chars = strncasecmp() [OK]Quick Trick: Use strncasecmp() for case-insensitive partial string compare [OK]Common Mistakes:Using strncmp() which is case-sensitiveUsing substr_compare() without case-insensitive flagUsing strcasecmp() without length limit
Master "String Functions" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Array Functions - Array reduce function - Quiz 8hard Classes and Objects - Object instantiation with new - Quiz 11easy Error and Exception Handling - Why error handling matters - Quiz 15hard File Handling - Directory operations - Quiz 4medium File Handling - Why file operations matter - Quiz 5medium File Handling - Writing files (fwrite, file_put_contents) - Quiz 13medium Inheritance and Polymorphism - Parent keyword behavior - Quiz 9hard Inheritance and Polymorphism - Type hinting with parent classes - Quiz 2easy Interfaces and Traits - Why traits are needed - Quiz 14medium String Functions - Substring extraction - Quiz 6medium