Note that this function will output the given $fields in the order they were added to the data array and not automatically in numerical key order.
To output in ascending key order, you'll need to ksort the array first (or use appropriate natural order sorting, depending on your keys).
For example:
<?php
$data[2] = 'C';
$data[0] = 'A';
$data[1] = 'B';
fputcsv($fh, $data); // outputs: "C,A,B"
ksort($data);
fputcsv($fh, $data); // outputs: "A,B,C"
?>