0

Can anyone share a resource (download or a how-to) for parsing a CSV to an associative array based on the first row of the CSV acting as the column names?

I found this resource http://blog.joshuamcginnis.com/2008/12/csv-to-associate-array/ but can't make heads or tales about the second parameter sent to the function.

In case you're unsure what I am speaking of, look at this.

CSV file
John,Smith,555-1212

would explode to

array (
 [0] => John,
 [1] => Smith,
 [2] => 555-1212
}

With the appropriate script, I want to take

CSV file
firstName,lastName,homePhone
John,Smith,555-1212

would explode to

array (
 [firstName] => John,
 [LastName] => Smith,
 [homePhone] => 555-1212
}

Good of you to take time to read this.

3
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by diafol
0

if you KNOW what to expect in cells 0,1,2 etc you can do a for next loop which creates an associative array with the names corresponding to the numeric array.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.