Jump to content

PHP to CSV- FPut running BACKWARDS?


scott.stephan

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.

Archived

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

×
×
  • 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.