Bird
0
0

Find the error in this PHP code:

medium📝 Debug Q6 of 15
PHP - String Functions
Find the error in this PHP code:
$text = 'example string';
$pos = strpos('string', $text);
echo $pos;
AMissing semicolon after echo
BVariable $pos is not defined
CParameters of strpos are reversed
Dstrpos cannot be used with strings
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter order in strpos

    The first parameter should be the full string to search in, second is the substring.
  2. Step 2: Identify the mistake

    Here, parameters are reversed: 'string' is searched in $text, but code searches $text in 'string'.
  3. Final Answer:

    Parameters of strpos are reversed -> Option C
  4. Quick Check:

    Parameter order matters in strpos = B [OK]
Quick Trick: First argument full string, second substring [OK]
Common Mistakes:
  • Swapping parameters order
  • Assuming strpos works with reversed args
  • Ignoring parameter order importance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes