$arr = array('');// 目标数组 header("Content-Type:application/vnd.ms-excel;charset=gbk"); header("Content-Disposition: attachment;filename='文件.csv'"); header('Cache-Control: max-age=0'); $fp = fopen('php://output', 'a'); $head = array('手机号', '姓名','职位', '公司'); foreach ($head as $i => $v) { $head[$i] = iconv('utf-8', 'gbk', $v); } fputcsv($fp, $head); foreach($arr as $vv){ $row = [$vv['phone'],$vv['username'],$vv['job'],($vv['company'])]; foreach ($row as $key => $val) { $row[$key] = iconv('utf-8', 'gbk', $val); } fputcsv($fp, $row); } ob_flush(); flush();