You may have been heading in the right direction originally with array_slice... This is off the top of my head, I don't guaruntee it will work...
$start = 34; $interval = 15; $max = 303; // hop across orig. array 15 columns at a time for($offset = $start; $offset < $max && isset($array[$offset]); $offset += $interval){ // slice off $interval many columns starting at $offset $sub_array = array_slice($array, $i, $interval); // handle your $interval many key-value pairs foreach ($sub_array as $key => $value){ $policyWriter = "$quoteKey|$key|$value"; // ... } } mh. On Fri, 31 May 2002, Scott wrote: > That's what I mean by starring at this too much :) I tried writting to a > seperate file, but is there a way to take an array and split it every so > many records within another loop? > > Let's say the first row contains the first 18 columns which I already > parsed, I then want to grab the next 5 15 columns, but need to seperate > them in groups of 15. I tried this: > > foreach ($output as $key => $value){ > $policyWriter = "$quoteKey|$key|$value"; > fwrite ($policyFile,"$policyWriter\r\n"); > } > > Which will take and print the rest of the row, but I needo split the > columns into groups of 15. > > -Scott > > > > > > On Fri, 31 May 2002, Michael Davey wrote: > > > You should normalise your data - have a field in the second csv that links > > to the first csv and then you can have as many rows as you want associated > > with the record in the first file. > > > > Mikey > > > > "Scott" <[EMAIL PROTECTED]> wrote in message > > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > > I have a csv file that I am parsing, formatting and then writting to a new > > > file. I am currently using an array, but I have some lines that might > > > contain more data than others. I know for sure that columns 0-33 will > > > always be there, but the customer has the option to add another set of > > > columns to the row if needed. I do know that the addition's will always > > > be 18 columns and I do know that they can add up to 15 set's of 18. So, > > > the row length could be 0-33 or 0-51 if they add one additional set or 303 > > > columns if they go up to 15. > > > > > > The tricky part is I have to format each column for the new file that is > > > created, I do this using sprintf. I have so far tried to use array_slice > > > for the first 18 columns, then I do another array_slice starting at 18 > > > and using the column count to get the last column in the row. Here is the > > > code: > > > > > > array_slice($fields, 18,$lineCount); > > > foreach ($fields as $key => $value){ > > > print "$key|$value\r\n"; > > > } > > > > > > The format of the new file will be this: > > > 01-Customer information > > > 02-Other information > > > 03a Required Info (that can repeat up to 15 times per line) > > > 03b "" > > > 04b "" > > > 04-Close Customer Record > > > > > > Repeat cycle for each row. The inner loop happens between the 02 and 04 > > > records. Remember, I need to format each individual column, they are > > > different format options. > > > > > > If you have some thoughts, I would be all ears as I have been starring at > > > this too long and too hard. > > > > > > Thanks, > > > > > > -Scott -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php