$data = array(
"title" => array("服务器", "链接", "对应ID"),
"第一行" => array("北京", "www.baidu.com", "13"),
"第一行" => array("上海", "www.baidu.com", "25"),
)
//注意: 如果字符编码是 UTF-8 的,要转换成GBK的
$new_data = array();
foreach ($data as $list) { //循环data数组
$data[] = array_map( function($v){return iconv('utf-8', 'gbk', $v); },$list); //转换list数组里元素 返回一个新数组
}
//$file_name 是文件名(可以带路径)
$fp = fopen($file_name, 'w');
foreach ($data as $line) {
fputcsv($fp, $line);
}
fclose($fp);