My solution requires the array be formatted differently than provided in the question: <? $data = array( array( 'row_1_col_1', 'row_1_col_2', 'row_1_col_3' ), array( 'row_2_col_1', 'row_2_col_2', 'row_2_col_3' ), array( 'row_3_col_1', 'row_3_col_2', 'row_3_col_3' ), ); ?>
We define our function:
Then we output our data as a CSV:
I have used this with several projects, and it works well. I should note that the outputCSV code is more clever than I am, so I am sure I am not the original author. Unfortunately I have lost track of where I got it, so I can't give the credit to whom it is due.