I have the following Array:
$a = array();
$handle = fopen('test.csv','r');
while (!feof($handle)){
$a = fgetcsv($handle,",");
}
fclose($handle);
echo $a[100];
Accompanied with the following CSV file (test.csv):
100,1245
500,111
600,12
I am getting the following error:
Notice: Undefined offset: 100
I don't understand what I am doing wrong. I have two columns, I want the first column to be the key, and the second column the value. I would then expect to have $a[100] return 1245. What am I missing? Why is this so hard?
EDIT
I want the first column to be the key and the second column to be the value. HOW do I achieve that goal? THAT is the question. Please don't get side tracked...
$a[100]does not exist. the array contains 3 items only, so only$a[0],$a[1], and$a[2], are valid. if you're creating a key/value array (whatever that's called in PHP), then use$a["100"]instead.var_dumporprint_rfor your reference.