I'm trying to read a csv file and then store the first and the 21st column in an associative array such that the 1st column becomes the key and 21st column becomes the value.
Later I would want to pull records based on the "key". The PHP file containing the code is upload.php
$calls = array();
$file_handle = fopen($C1.".File.csv","r"); // $C1 is defined before.
//Just appending something to the file name. This file exists.
while (!feof($file_handle) ) {
$line= fgetcsv($file_handle, 1024);
$calls[$line[0]] = $line[20]; //Line 94 of this file
}
fclose($file_handle);
print_r($calls);
I get this error
Undefined offset: 20 in upload.php on line 94
Where am I going wrong.
fgetcsv()function manual: php.net/manual/en/function.fgetcsv.php