Jump to content

Recommended Posts

Basically, I need a lead row on my .csv file. I created the string, I created the putfile. Everything runs perfectly. EXCEPT, no matter how I do, the lead row is ALWAYS the last row in the file. Does fputcsv run BACKWARDS? Here's the code:

 

	$leadrow="ORDER,DATE,TYPE,PRIORITY,PO,EMAIL,SHIPVIA,SHIPAFTER,CUSTOMERID,BILLTONAME,BILLTOSTREET,BILLTOSTREET2,BILLTOCITY,BILLTOSTATE,BILLTOZIP,BILLTOCOUNTRY,BILLTOCONTACT,SHIPTONAME,SHIPTOSTREET,SHIPTOSTREET2,SHIPTOCITY,SHIPTOSTATE,WHIPTOZIP,SHIPTOCOUNTRY,SHIPTOCONTACT,SHIPTOPHONE,SKU,DESC,QTYORDERED,QTYSHIPPED,QTYBACKORDERED,3RDPARTYSHIP,3RDPARTACCT,NOTES";
	$list[0]=$leadrow;

  
$fp = fopen('TodfdsdfdfCO3.csv', 'w');

foreach ($list as $line) {
	fputcsv($fp, split(',', $line));
}

fclose($fp);

 

And the output is the contents of $list followed by the lead row in dead last place, even though it should be in position 0. Thoughts?

 

Link to comment
https://forums.phpfreaks.com/topic/162082-php-to-csv-fput-running-backwards/
Share on other sites

The array elements are added in the order that the code adds them and that is the order that the foreach() loop operates on them. There is nothing magic about an array index [0] unless you sort the array or iterate over the array using ordered numeric index values.

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.