Jump to content

CSV Multidimensional Array


verdrm

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?

Link to comment
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;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.