Bird
0
0

What will the following PHP code output?

medium📝 Predict Output Q5 of 15
PHP - File Handling
What will the following PHP code output?
$files = scandir('myfolder');
print_r($files);
Assuming myfolder contains files a.txt and b.txt.
AError: scandir() undefined
BArray with '.', '..', 'a.txt', 'b.txt'
CBoolean false
DArray with only 'a.txt' and 'b.txt'
Step-by-Step Solution
Solution:
  1. Step 1: Understand scandir() output

    scandir() returns an array including '.' and '..' plus all files and directories inside.
  2. Step 2: List expected array elements

    Since 'myfolder' has 'a.txt' and 'b.txt', the array will be ['.', '..', 'a.txt', 'b.txt'].
  3. Final Answer:

    Array with '.', '..', 'a.txt', 'b.txt' -> Option B
  4. Quick Check:

    scandir() includes '.' and '..' entries [OK]
Quick Trick: scandir() always includes '.' and '..' entries [OK]
Common Mistakes:
  • Expecting only files without '.' and '..'
  • Thinking scandir() returns false on success
  • Assuming scandir() is undefined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes