Bird
0
0

Which of the following is the correct syntax to read a CSV line into an array in PHP?

easy📝 Syntax Q3 of 15
PHP - File Handling
Which of the following is the correct syntax to read a CSV line into an array in PHP?
A$data = fgetcsv($file);
B$data = fgets($file);
C$data = freadcsv($file);
D$data = fputcsv($file);
Step-by-Step Solution
Solution:
  1. Step 1: Identify function to read CSV lines

    fgetcsv() reads a line from a file and parses it as CSV into an array.
  2. Step 2: Exclude incorrect functions

    fgets() reads a line as string, freadcsv() doesn't exist, fputcsv() writes CSV.
  3. Final Answer:

    $data = fgetcsv($file); -> Option A
  4. Quick Check:

    Read CSV line syntax = fgetcsv() [OK]
Quick Trick: Use fgetcsv() to read CSV lines as arrays [OK]
Common Mistakes:
  • Using fgets() which returns string
  • Assuming freadcsv() exists
  • Mixing fputcsv() with reading

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes