I'm exporting an array to a csv file, but I'm having trouble with formatting

This is the array:

Array ( [0] => Array ( [id] => 41 [item] => HY87MB [cost] => $43,679 ) [1] => Array ( [id] => 39 [item] => UYITHO [cost] => $79,202.10 ) )

And the csv file looks like this:
41,HY87MB,$43,679
39,UYITHO,$9,202.10

When, I want it to look like this:
41,"HY87MB","$43,679"
39,"UYITHO","$9,202.10"

Here's the code I'm using:

$fp = fopen(testfile.csv', 'w');
foreach($result as $line) {
                foreach($line as $line2) {
                                fputcsv($fp, split(',',$line2));
                }
}
fclose($fp);
header('Location: testfile.csv');
    <?
    
    //I would do that like this...
    
    function f_num($data)
    {
    if(is_numeric($data))
    return $data;
    else
    return '"'.$data. '"';
    }
    
    //And use the array_map function to create that...
    $result=array_map("f_num",$old_array);
    
    // and then its your program.
    
    $fp = fopen(testfile.csv', 'w');
    foreach($result as $line) {
                    foreach($line as $line2) {
                                    fputcsv($fp, split(',',$line2));
                    }
    }
    fclose($fp);
    header('Location: testfile.csv'); 
    ?>
    
      Write a Reply...