How can I write to a CSV file in PHP? Example code: - Biz Tech

How can I write to a CSV file in PHP? Example code:

Listen
$filename = "data.csv";
$file = fopen($filename, "a");

$name = "John Doe";
$email = "[email protected]";

// Write data to file
fwrite($file, $name . "," . $email . "\n");

fclose($file);