What are the differences between using fwrite and fputcsv for writing data to a text file in PHP?

When writing data to a text file in PHP, `fwrite` is a general-purpose function that allows you to write raw data to a file, while `fputcsv` is specifically designed for writing data in CSV format, automatically handling delimiters and escaping special characters. If you are writing data that needs to be in CSV format, it is recommended to use `fputcsv` for simplicity and accuracy.

// Example using fputcsv to write data to a CSV file
$data = array(
    array('John', 'Doe', 30),
    array('Jane', 'Smith', 25),
);

$fp = fopen('data.csv', 'w');

foreach ($data as $fields) {
    fputcsv($fp, $fields);
}

fclose($fp);