What are the potential benefits of storing form data in a CSV file using PHP?

Storing form data in a CSV file using PHP can be beneficial for easily managing and accessing the submitted information. It allows for structured storage of data that can be easily imported into spreadsheet applications for further analysis. Additionally, CSV files are lightweight and can be easily shared or transferred between systems.

// Assuming form data is submitted via POST method
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $data = [];
    foreach ($_POST as $key => $value) {
        $data[] = [$key, $value];
    }

    $file = fopen('form_data.csv', 'a');
    foreach ($data as $fields) {
        fputcsv($file, $fields);
    }
    fclose($file);
}