I need to add form input data from an array to a CSV file in PHP.
I tried to add the data with foreach function but the data didn't appear in the CSV file with the following code:
$values = [
'orderperson',
'address',
'postnumber',
'city',
'phone',
'email'
];
$fh = fopen("file.csv", "w");
foreach($values as $info) {
fputcsv($fh, $_POST[$info]);
}
If I'm correct what I'm trying to accomplish here puts all the data in one row? How I can add the data in the file like that there's only one element of array in one row like this:
1 orderperson
2 address
3 postnumber
and not like 1 orderperson 2 address 3 postnumber