Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q7 of 15
PHP - File Handling
What is wrong with this code snippet?
$lines = file('data.txt');
echo $lines;
AMissing fopen() before file()
Bfile() requires a second parameter
Cfile() returns a string, not array
Dfile() returns an array, echo cannot print array directly
Step-by-Step Solution
Solution:
  1. Step 1: Understand file() return type

    file() returns an array of lines, not a string.
  2. Step 2: Check echo behavior with arrays

    echo cannot output arrays directly, causing an error or warning.
  3. Final Answer:

    file() returns an array, echo cannot print array directly -> Option D
  4. Quick Check:

    echo cannot print arrays directly [OK]
Quick Trick: Use print_r() or loop to display arrays [OK]
Common Mistakes:
  • Trying to echo an array directly
  • Expecting file() to return string
  • Not using fopen() before file() (not needed)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes