Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - File Handling
What will be the output of this PHP code?
$file = fopen('test.csv', 'w');
fputcsv($file, ['apple', 'banana', 'cherry']);
fclose($file);
echo file_get_contents('test.csv');
Aapple;banana;cherry
Bapple,banana,cherry
Capple|banana;cherry
Dapple banana cherry
Step-by-Step Solution
Solution:
  1. Step 1: Understand fputcsv default delimiter

    fputcsv writes array elements separated by commas by default.
  2. Step 2: Check output of file_get_contents

    Reading the file shows the line with commas and a newline character.
  3. Final Answer:

    apple,banana,cherry -> Option B
  4. Quick Check:

    Default CSV delimiter = comma [OK]
Quick Trick: fputcsv uses commas by default as separators [OK]
Common Mistakes:
  • Expecting semicolons or pipes
  • Ignoring newline at line end
  • Confusing output with echo of array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes