Bird
0
0

What does the PHP function file() return when reading a file?

easy📝 Conceptual Q2 of 15
PHP - File Handling
What does the PHP function file() return when reading a file?
AAn array where each element is a line from the file
BA string containing the whole file content
CA file pointer resource
DThe number of bytes read
Step-by-Step Solution
Solution:
  1. Step 1: Recall the behavior of file()

    The file() function reads the entire file and returns an array where each element is a line from the file including newline characters.
  2. Step 2: Compare options with function behavior

    An array where each element is a line from the file matches this behavior exactly. Other options describe different functions or return types.
  3. Final Answer:

    An array where each element is a line from the file -> Option A
  4. Quick Check:

    file() returns array of lines = An array where each element is a line from the file [OK]
Quick Trick: file() returns lines as array elements [OK]
Common Mistakes:
  • Thinking file() returns a string
  • Confusing file() with fopen()
  • Expecting file() to return a file pointer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes