Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - Array Functions
What will be the output of this PHP code?
$data = ['name' => 'John', 'age' => 25];
extract($data);
echo "$name is $age years old.";
Aname is age years old.
BJohn is 25 years old.
CError: Undefined variables
DArray to string conversion error
Step-by-Step Solution
Solution:
  1. Step 1: Understand extract effect

    extract creates variables $name and $age from the array keys with their values.
  2. Step 2: Output string with variables

    After extraction, $name is 'John' and $age is 25, so the echo prints "John is 25 years old."
  3. Final Answer:

    John is 25 years old. -> Option B
  4. Quick Check:

    extract creates variables from array keys [OK]
Quick Trick: extract creates variables from array keys [OK]
Common Mistakes:
  • Not calling extract before echo
  • Expecting array print
  • Confusing variable names with strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes