I am uploading a CSV file/report with 10 columns but at the end of the CSV file there are a few lines that just give details about the report like
Generated By: XXX
Company Name
Report Run @ 2019-03-14
When I load the array, the keys are just numeric (from 0-9) but I wanted to make it be an associative array based on the column headers. Unfortunately this will not work for the last few lines since the array dimensions are different (1 vs 10)
Here is my code:
$csv = array_map('str_getcsv', file($_FILES['file']['tmp_name']));
array_walk($csv, function(&$a) use ($csv) {
if(count($csv[0]) != count($a)) {
$a = null; // Remove the array
} else {
$a = array_combine($csv[0], $a);
}
});
array_shift($csv); # remove column header
When I do $a = null;
it sort of 'deletes it' by replacing it with NULL
. When I iterate through the arrays I do if(is_null($row)) continue;
to ignore the NULL
element. Is there a way to actually delete the array?