如何将csv导入到关联数组并自动命名键?

I have a csv file where the first line shows the name of each row. This name should be the key for an associative array. Currently I am pulling this in manually and if the row order changes it will break the functionality.

How can I retrieve the names from line 1 and create keys out of it?

$csv = array();
$index = 0;
while ($row = fgetcsv($fp)) {
    if ($row[0] == NULL) 
        continue;
    else{
        $index++;
        foreach($row as $csvdata){
            list(
                $csv[$index]['column 1 name'],
                $csv[$index]['column 2 name']
            )
            = explode(';',$csvdata);
        }
    }
}

Try converting the very first line of the file, which contains the names/keys, into an array. Then use those keys to populate the associate array as you parse the remaining lines.

$keys = array();
$csv = array();
$index = 0;
while ($row = fgetcsv($fp)) {
    if ($index == 0) {
        $keys = explode(',', $row);
    }
    else {
        $csv[$keys[index-1]] = $row;
    }
    ++$index;
}

This answer assumes that what you want here is an associate array where the keys correspond to the names in the first row, and the values correspond to each row in the CSV import.