verdrm Posted October 30, 2011 Share Posted October 30, 2011 I need to extract data from a CSV file and insert it into a MySQL database. I am able to extract the data, however I cannot figure out how to group it. Sample File: 01 ISBN Name of Book Price 02 ISBN Name of Book Price So far I have an array with the entire file (reading file with PHP): Array ([0] => 01 [1] => 12345678X [2] => Title [3] => 120.00 ...etc. How can I modify the array to create groups of four for each item? Each item is its own array? Link to comment https://forums.phpfreaks.com/topic/250128-csv-multidimensional-array/ Share on other sites More sharing options...
n3r0x Posted October 31, 2011 Share Posted October 31, 2011 would do something like this. $storage_array = array(); // Split it into rows $parts = explode("\n",$file); $x=0; // For each row foreach ($parts AS $v) { // This one depends on the format of your file if they use tab it should have \t and so on // Split into elements $storage_array[$x] = explode("\t",$v); ++$x; } Link to comment https://forums.phpfreaks.com/topic/250128-csv-multidimensional-array/#findComment-1283705 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.