如何将数组转换为csv

时间:2019-04-09 15:18:04

标签: php

是否存在任何可以将这些数组转换或转换为CSV文件的PHP代码?

  

数组([0] =>垃圾[1] =>不良[2] =>仇恨[3] =>废弃[4] =>滥用[5] =>被指控[6] =>沉迷[7] =>害怕[8] =>加剧[9] =>进取[10] =>孤独[11] =>愤怒[12] =>痛苦[13] =>恼火[14] =>焦虑[15] =>忧虑[16] =>辩论[17] =>人为[18] =>羞愧[19] =>受到攻击[20] =>残暴[21] =>受攻击[22] =>避免[23] =>糟糕[ 24] =>尴尬[25] =>徽章[26] =>困惑[27] =>被禁止[28] =>贫瘠[29] =>殴打[30] =>殴打)

1 个答案:

答案 0 :(得分:0)

您可以使用fopenfputcsv函数来写入csv文件。确保路径可写。

$rowData = array(
    array(1,2,3),
    array(1,2,3),
);

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

foreach ($rowData as $fields) {
    fputcsv($fp, $fields);
}
fclose($fp);

有关更多详细信息,请参阅PHP Manual