thephpleague / csv

CSV data manipulation made easy in PHP
https://csv.thephpleague.com
MIT License
3.33k stars 333 forks source link

Notice: Undefined index #458

Closed chrisooo3 closed 2 years ago

chrisooo3 commented 2 years ago

My csv file looks like this:

"Col1";"Col2";"Col3";Col4;Col5;
2869;"=""510015171""";"=""7393077918""";Test;"Name";

After executing this code:

        $reader = Reader::createFromPath('/file.csv');
        $reader->setDelimiter(';');

        $records = $reader->getRecords();
        foreach ($records as $record) {
            dump($record['Col1']);
        }

I am getting the following error:

WARNING   [php] Notice: Undefined index: Col1

The format of CSV file is correct because it opens in libre office correctly.

nyamsprod commented 2 years ago

@chrisooo3 thanks for using the library. The package does not autodetect headers you need to specify the header row as explain in the documentation.