多维数组+ CSV导出

时间:2016-06-09 03:03:17

标签: php arrays csv

我在尝试编写导出脚本时出现问题...

  1. 我创建了一个多维数组

    while($ row = $ insert_row-> fetch_assoc()){

        foreach ($selectArray as $value) {
            $userData = $row[$value];
            $userDataArray[] = $userData;
        }
        $userArray[] = $userDataArray;
        unset($userDataArray);
    }
    
  2. 现在我要创建CSV文件

    $ sendfilename =“export”。名为 “.csv”;     $ filename =“file”。名为 “.csv”;     $ delimiter =';';     $ enclosure ='“';     $ encloseAll = true;     $ nullToMysqlNull = false;     $ delimiter_esc = preg_quote($ delimiter,'/');     $ enclosure_esc = preg_quote($ enclosure,'/');

    $fp = fopen($filename, 'wb');
    
    if ($fp)
    {
        foreach ($userArray as $users) {
            foreach ($users as $fields) {
                fputcsv($fp, $fields,";",'"');
            }
        }
    }
    fclose($fp);
    readfile($filename);
    
  3. 我得到错误“fputcsv()期望参数2是数组,字符串给出”

    任何解决方案?

1 个答案:

答案 0 :(得分:0)

已经修好了,我在一个级别上深入了解...