Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数组_唯一和XLS导出_Php_Arrays_Xls - Fatal编程技术网

Php 数组_唯一和XLS导出

Php 数组_唯一和XLS导出,php,arrays,xls,Php,Arrays,Xls,所以我想将我的数据库导出为XLS格式。。。这是我的密码 $req_test = $db->prepare('SELECT `surname`, `name`, `num`, `email`, `password`, `rank` FROM staff'); $req_test->execute(); $array = $req_test->fetchAll(); $array = array_unique($array); print_r($array); head

所以我想将我的数据库导出为XLS格式。。。这是我的密码

$req_test = $db->prepare('SELECT `surname`, `name`, `num`, `email`, `password`, `rank` FROM staff');
$req_test->execute();


$array = $req_test->fetchAll();

$array = array_unique($array);

print_r($array);


header("Content-Disposition: attachment; filename=\"demo.xls\"");
header("Content-Type: application/vnd.ms-excel;");
header("Pragma: no-cache");
header("Expires: 0");
$out = fopen("php://output", 'w');
foreach ($array as $data)
{
fputcsv($out, $data,"\t");
}
fclose($out);
因此,如果没有数组_unique,它将返回以下内容:

Array ( [0] => Array ( [surname] => test [0] => test [name] => test [1] => test [num] => 2424242424 [2] => 2424242424 [email] => test@gmail.com [3] => test@gmail.com [password] => 123456 [4] => 123456 [rank] => admin [5] => admin ) [1] => Array ( [surname] => Markus [0] => Markus [name] => Tasse [1] => Tasse [num] => 052424524 [2] => 052424524 [email] => ad@gmail.com [3] => ad@gmail.com [password] => us01PjIOx2 [4] => us01PjIOx2 [rank] => staff [5] => staff ) ) 
我有一个错误:

( ! ) Notice: Array to string conversion in C:\wamp3.2.0\www\project\export.php on line 15

我能做什么?谢谢。

我不知道代码中的哪一行是“第15行”,但如果该行是“fputcsv($out,$data,“\t”);“我想在假装将$data变量像字符串一样输出到文件之前,需要将其展平。我猜$data变量保存了所有粘贴的字段,所以要么你选择1by1,要么它就不起作用了我猜一切正常,但数组_unique出现了错误。你对数组_unique的实际期望是什么?要删除克隆的条目,我想你应该直接从SQL查询中获取唯一的数据,不必费心用PHP来做这件事