In your loop, there is no need to modify the copy of the array row (with unset()
, array_shift()
, etc.), simply deliver the column value that you wish to use as a single-element array.
The second parameter of fputcsv() MUST be an array. This is why the $row[0]
value is wrapped in square brackets.
If you want to save the name values to your file, use $row[0]
.
If you want to save the numeric values to your file, use $row[1]
.
Code:
$test = ["eric", 7], ["nancy", 8], ["dave", 10]];
$fp = fopen("new.csv", 'w');
foreach ($test as $row) {
fputcsv($fp, [$row[0]]); // if you want first column values
}
fclose($fp);