I am looping over an array,
if I spot an error in the array I am adding a key called error.
however I am getting a whole pile of 'undefined index 'error' warnings.
How can I do this without generating those warnings?
Code as requested
$csv = array();
if (($handle = fopen($filePath, "r")) !== FALSE) {
while (($csv[] = fgetcsv($handle)) !== FALSE);
fclose($handle);
}
foreach ($csv as &$row) {
if (count($row) > $maxCols)
$maxCols = count($row);
if (count($row) == 0) {
$errors++;
$row['error'] = 'Empty Column!';
continue;
}
//more code
}
Example of what $row would look like in the
foreach()
Array (
[0] => 1
[1] => 12
[2] => 64273566141
[3] => bakery
[4] => 2009-12-08 09:07:39
[5] => 2009
[6] => 2009-12-08 09:08:35
[7] =>
[8] => 0 )
See? Full Size

fgetcsv
– Hailwood Feb 17 '11 at 1:27isset
orarray_key_exists
are the usual solutions to this error, but code please, cause given what you are describing you shouldn't be getting this error unless i've misunderstood what you are asking – tobyodavies Feb 17 '11 at 1:30//more code
comment please) – tobyodavies Feb 17 '11 at 1:33