Q:

PHP - putcsv by specific column

I want to putcsv by specific column for example:
$fp = fopen("testing.csv", 'w');
//this is the header
fputcsv($fp, array("title","price","image1","image2","image3","shipping1","shipping2"));
//this is what i want to put
fputcsv($fp, array("title" => "test title","price" => "90","image1" => "test.jpg","image2","image3","shipping1" => "forex","shipping2"));
//and then set another null (like image2,images3, and shipping2)

A:

you can try this
$fp = fopen("testing.csv", 'w');
    //this is the header
    fputcsv($fp, array("title","price","image1","image2","image3","shipping1","shipping2"));

// skeleton array with empty strings
$skeletonArr = array("title" => "","price"=> "","image1"=> "","image2"=> "","image3"=> "","shipping1"=> "","shipping2"=> "");
//merge the entries with the skeleton to keep the order, apply array_values on the resulting array
fputcsv($fp, array_values(array_merge($skeletonArr, array("title"=>"test title","price"=>"90", "image1"=>"test.jpg", "shipping1"=>"forex"))));

