The following code exports the whole array into the .csv file, but I only want to export a specific column.
<?php
$test = array(array("eric", 7),array("nancy" ,8),array("dave", 10));
$fp = fopen('new.csv', 'w');
foreach ($test as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
?>
You can do this by removing the fields you want to exclude from the $fields array before calling fputcsv(). Remove the fields using the unset() function passing the element's key.
Example
Assuming you want to have only a list of the name, you'd do the following