This is a discussion on CSV to associative arrays within the PHP General forums, part of the PHP Programming Forums category; Hi all, Kind of a PHP newbie and was wondering if anyone could provide some guidance. I have 2 CSV ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi all,
Kind of a PHP newbie and was wondering if anyone could provide some guidance. I have 2 CSV files with 2 columns each and want to find the intersection of both based on the value in the first column. For example File 1 id1, apple id2, orange id3, banana id4, durian id5, tomato File 2 id7, coke id6, drpepper id5, sprite id4, 7up id1, water My desired output is: id1, apple, water id4, durian, 7up id5, tomato, sprite I've been trying to create some PHP scripts to do that, using merge, usort, array_intersect. I think my main problem is that when use fgetcsv, I'm creating multi-dimensional arrays. I *think* what I should be doing is creating single dimension arrays with IDs as keys, and the fruit/drink as values. Then I should be able to use array_intersect_assoc to compare the keys from each list and match IDs. However, I don't know how to go from id1, apple to array(id1 => apple). Anyone know how I can read the CSV files in this way? Am i on the right track? Thanks! |