Create CSV from multidimensional array with fputcsv

♀尐吖头ヾ 提交于 2019-12-01 19:17:30
Ja͢ck

I would suggest to flatten each array first:

foreach ($csv as $file) {
    $result = [];
    array_walk_recursive($file, function($item) use (&$result) {
        $result[] = $item;
    });
    fputcsv($output, $result);
}

In each iteration it would create an array like this:

[1111, 'Alcatel One Touch Idol 2', 'alcatel-one-touch-idol-2', 54, 42, ...]
foreach ($data as $line) {
    foreach($line as $array){
        foreach($array as $result){
            fputcsv($f,$result,",");
        }
    }
}

i know its an old question but you could also use this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!