Bird
0
0

What will be the output of this PHP code?

medium📝 Predict Output Q5 of 15
PHP - File Handling
What will be the output of this PHP code?
$file = fopen('data.csv', 'w');
fputcsv($file, ['John', 'Doe', 30]);
fclose($file);
$file = fopen('data.csv', 'r');
$row = fgetcsv($file);
fclose($file);
echo $row[1];
ADoe
B30
CJohn
DArray
Step-by-Step Solution
Solution:
  1. Step 1: Write CSV line with fputcsv

    Array ['John', 'Doe', 30] is written as CSV line.
  2. Step 2: Read CSV line with fgetcsv and access index 1

    fgetcsv returns array; index 1 is 'Doe'.
  3. Final Answer:

    Doe -> Option A
  4. Quick Check:

    CSV index 1 = 'Doe' [OK]
Quick Trick: CSV arrays start at index 0; index 1 is second element [OK]
Common Mistakes:
  • Printing index 0 instead of 1
  • Expecting '30' at index 1
  • Echoing array directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes