I'm parsing a large CSV file using SplFileObject
. This CSV has almost 100,000 records and mutliple columns.
Some of these columns are empty.
I have the following code:
$file = new SplFileObject($uploadedFile);
$file->setFlags(SplFileObject::READ_CSV);
// ignore the header
$it = new LimitIterator($file, 1);
foreach ($it as $row) {
list(
$email,
$name) = $row;
}
When I run the script, I always get an error:
PHP Notice: Undefined offset: 1 in script.php on line 5
PHP Notice: Undefined offset: 2 in script.php on line 5
............
PHP Notice: Undefined offset: 35 in script.php on line 5
Line 5 is the actual list() = $row
Is there a way I can fix this? Maybe by checking that the array has values?
Thanks