Jump to content

Archived

This topic is now archived and is closed to further replies.

verdrm

CSV Multidimensional Array

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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;
}

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.