Bird
0
0

Why does the following PHP code print "Array"?

hard📝 Conceptual Q10 of 15
PHP - Output and String Handling
Why does the following PHP code print "Array"?
print ["a" => "apple", "b" => "banana"];
Aprint throws an error when printing arrays
Bprint converts array to string by joining values
Cprint outputs all array elements separated by commas
Dprint cannot output arrays, so it prints "Array"
Step-by-Step Solution
Solution:
  1. Step 1: Understand print and arrays

    print cannot directly output arrays; it expects strings or numbers.
  2. Step 2: What happens with arrays

    Passing an array to print causes it to output 'Array' (with an array-to-string warning).
  3. Final Answer:

    print cannot output arrays, so it prints "Array" -> Option D
  4. Quick Check:

    print fails on arrays = A [OK]
Quick Trick: Use print_r or var_dump for arrays, not print [OK]
Common Mistakes:
  • Expecting print to output arrays directly
  • Assuming arrays convert to strings automatically
  • Not using correct functions for arrays

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes