I\'m trying to get a multidimensional array into a csv file. data in the array is as such:
Array
(
[0] => Array
(
[product_id] => 1111
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