How to generate sample csv file using php

Here is the code to generate the sample csv file that downloads directly by hitting the url.

header("Content-Disposition:attachment;filename=travel-plan-sample-".date("ymdhis").".csv");
header("Pragma: no-cache");
header("Expires: 0");
$headers = $body =  "";
$response = array(
        0 = array(
                     'ID' = '',
                     'NAME' = ''
                  )
)
foreach($response as $k=$val)
{
  if($k==0)
    {
      // col heads
      foreach ($val as $k=$v)
      $headers .= $k.",";
    }
    $body .= implode(',',$val)."\n";

}
$headers = substr($headers,0,strlen($headers)-1);
$body = substr($body,0,strlen($body)-1);
echo $headers."\n";
echo $body;