Bird
0
0

Find the problem in this PHP code snippet:

medium📝 Debug Q7 of 15
PHP - Array Functions
Find the problem in this PHP code snippet:
$info = ['color' => 'red', 'size' => 'large'];
extract($info, EXTR_PREFIX_SAME, 'dup');
echo $color . ', ' . $dup_size;
ASyntax error in extract call
Bextract does not support prefixes
CVariables $color and $size are not created
DVariable $dup_size is not created due to no duplicate keys
Step-by-Step Solution
Solution:
  1. Step 1: Understand extract with prefix

    Using EXTR_PREFIX_SAME adds a prefix to variables if a name conflict exists.
  2. Step 2: Analyze variables created

    Since $size does not exist before, it is created normally. If a conflict existed, $dup_size would be created. Here, $dup_size is created only if conflict occurs.
  3. Final Answer:

    Variable $dup_size is not created due to no duplicate keys -> Option D
  4. Quick Check:

    extract with prefix adds prefix on duplicates [OK]
Quick Trick: extract prefixes duplicate variable names [OK]
Common Mistakes:
  • Assuming no prefix support
  • Expecting no variables created
  • Confusing prefix behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes