Hello All,
It’s been a while since I’ve been on here and hope you are all doing well.
I’m having a bit of problem of creating an associative array from an TSV/CVS file upload. It’s a just something I’m trying to work on to improve upon what I’m able to do but it’s really gotten me frustrated.
I am able to build a multidimensional array from the TSV file I have, I just can’t figure out how to make it an associative one.
Below is my current function to build the multidimensional array. I’ve never really worked with any delimited files before so kind of banging my head against the all trying to get this to work.
If anyone could give me advice on how to associate the headers with the data they belong to I’d appreciate it.
Thanks,
Valandor
[php]public function tsv_to_array(){
//Open File
if(($handle = fopen($this->file, ‘r’)) !==FALSE){
//Set Parent For Multidimentional Array To 0
$nn = 0;
while(($data = fgetcsv($handle, 0, “\t”)) !== FALSE){
$num = count($data);
//Populate Multidimentional Array
for ($x=0; $x < $num -1; $x++){
$tsvarray[$nn][$x] = $data[$x];
}
$nn++;
}
//Close File
fclose($handle);
}
//Return Array
return($tsvarray);
}// End tsv_to_array [/php]