I'm able to get the file into an array, but I'd like to get the key's to be the first row. Here's is the curl command:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://url.com/download");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "X-App-Key: xxxxx";
$headers[] = "X-User-Key: yyyy";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
$data = array_map("str_getcsv", preg_split('/\r*\n+|\r+/', $result));
return $data;
Here is the csv that is returned:
"Date,Campaign,Campaign Id,Impressions,Clicks,CTR,Platform Cost,Search Cost,Demographic Cost,Contextual Cost,Behavioral Cost,Geographic Cost,Segment Cost,Media Cost,CPM,Total Spend,ECPC,Click Sales,Click Leads,Click Signups,Click Other,View Sales,View Leads,View Signups,View Other,CPA,Weighted Actions 2017-05-16,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,2,,2.00 2017-05-18,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,2,,2.00 2017-05-19,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,2,,2.00 2017-05-20,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,2,,2.00 2017-05-28,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,1,,1.00 2017-06-02,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,1,,1.00 2017-05-10,Company,326606,16877,41,0.002429,0.770373,0.000000,0.0,0.000000,0.0,0.770373,0.000000,1.540785,3.081682,52.009548,1.268526,,,,,,,,,, 2017-05-11,Company,326606,17001,50,0.002941,0.764775,0.000000,0.0,0.000000,0.0,0.764775,0.000000,1.529592,3.059288,52.010956,1.040219,,,,,,,,,, 2017-05-12,Company,326606,16814,44,0.002617,0.773364,0.000000,0.0,0.000000,0.0,0.773364,0.000000,1.546763,3.093651,52.016652,1.182197,,,,,,,,,, 2017-05-13,Company,326606,16880,32,0.001896,0.770245,0.000000,0.0,0.000000,0.0,0.770245,0.000000,1.540520,3.081195,52.010570,1.625330,,,,,,,,,, 2017-05-14,Company,326606,17045,32,0.001877,0.762742,0.000000,0.0,0.000000,0.0,0.762742,0.000000,1.525543,3.051212,52.007907,1.625247,0,0,0,0,0,0,0,1,52.0079,1.00 2017-05-15,Company,326606,7294,10,0.001371,0.781126,0.000000,0.0,0.000000,0.0,0.781126,0.000000,1.562252,3.124683,22.791441,2.279144,,,,,,,,,, 2017-06-03,Company,559435,30186,42,0.001391,0.690422,0.690422,0.0,0.000000,0.0,0.000000,0.000000,1.380910,2.761773,83.366884,1.984926,0,0,0,1,0,0,0,1,41.6834,2.00 2017-06-04,Company,559435,29952,25,0.000835,0.695962,0.695962,0.0,0.000000,0.0,0.000000,0.000000,1.391983,2.783917,83.383894,3.335356,0,0,0,0,0,0,0,12,6.9487,12.00 2017-06-05,Company,559435,29863,39,0.001306,0.697854,0.697854,0.0,0.000000,0.0,0.000000,0.000000,1.395772,2.791494,83.362371,2.137497,0,0,0,4,2,1,0,15,3.7892,22.00 2017-06-06,Company,559435,29859,40,0.001340,0.698055,0.698055,0.0,0.000000,0.0,0.000000,0.000000,1.396160,2.792283,83.374777,2.084369,0,1,0,4,2,1,0,21,2.8750,29.00 2017-06-07,Company,559435,29968,22,0.000734,0.695653,0.695653,0.0,0.000000,0.0,0.000000,0.000000,1.391359,2.782683,83.391458,3.790521,0,0,0,1,0,0,0,25,3.2074,26.00 2017-06-08,Company,559435,29967,41,0.001368,0.695284,0.695284,0.0,0.000000,0.0,0.000000,0.000000,1.390634,2.781195,83.344075,2.032782,0,0,0,2,1,0,0,23,3.2055,26.00 2017-06-09,Company,559435,14689,8,0.000545,0.686755,0.686755,0.0,0.000000,0.0,0.000000,0.000000,1.373565,2.747041,40.351291,5.043911,0,0,0,0,0,2,0,21,1.7544,23.00 ,,,286395,426,0.001487,0.718754,0.471867,0.0,0.000000,0.0,0.246886,0.000000,1.437560,2.875126,823.421824,1.932915,0,1,0,12,5,4,0,129,5.4531,151.00
And the returned array is but I'd like "date" "clicks" to be used as the keys so I can simply call "$data[Click Lead]":
array(22) {
[0]=>
array(27) {
[0]=>
string(4) "Date"
[1]=>
string(8) "Campaign"
[2]=>
string(11) "Campaign Id"
[3]=>
string(11) "Impressions"
[4]=>
string(6) "Clicks"
[5]=>
string(3) "CTR"
[6]=>
string(13) "Platform Cost"
[7]=>
string(11) "Search Cost"
[8]=>
string(16) "Demographic Cost"
[9]=>
string(15) "Contextual Cost"
[10]=>
string(15) "Behavioral Cost"
[11]=>
string(15) "Geographic Cost"
[12]=>
string(12) "Segment Cost"
[13]=>
string(10) "Media Cost"
[14]=>
string(3) "CPM"
[15]=>
string(11) "Total Spend"
[16]=>
string(4) "ECPC"
[17]=>
string(11) "Click Sales"
[18]=>
string(11) "Click Leads"
[19]=>
string(13) "Click Signups"
[20]=>
string(11) "Click Other"
[21]=>
string(10) "View Sales"
[22]=>
string(10) "View Leads"
[23]=>
string(12) "View Signups"
[24]=>
string(10) "View Other"
[25]=>
string(3) "CPA"
[26]=>
string(16) "Weighted Actions"
}
[1]=>
array(27) {
[0]=>
string(10) "2017-05-16"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "2"
[25]=>
string(0) ""
[26]=>
string(4) "2.00"
}
[2]=>
array(27) {
[0]=>
string(10) "2017-05-18"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "2"
[25]=>
string(0) ""
[26]=>
string(4) "2.00"
}
[3]=>
array(27) {
[0]=>
string(10) "2017-05-19"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "2"
[25]=>
string(0) ""
[26]=>
string(4) "2.00"
}
[4]=>
array(27) {
[0]=>
string(10) "2017-05-20"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "2"
[25]=>
string(0) ""
[26]=>
string(4) "2.00"
}
[5]=>
array(27) {
[0]=>
string(10) "2017-05-28"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "1"
[25]=>
string(0) ""
[26]=>
string(4) "1.00"
}
[6]=>
array(27) {
[0]=>
string(10) "2017-06-02"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "1"
[25]=>
string(0) ""
[26]=>
string(4) "1.00"
}
[7]=>
array(27) {
[0]=>
string(10) "2017-05-10"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(5) "16877"
[4]=>
string(2) "41"
[5]=>
string(8) "0.002429"
[6]=>
string(8) "0.770373"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.770373"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.540785"
[14]=>
string(8) "3.081682"
[15]=>
string(9) "52.009548"
[16]=>
string(8) "1.268526"
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(0) ""
[21]=>
string(0) ""
[22]=>
string(0) ""
[23]=>
string(0) ""
[24]=>
string(0) ""
[25]=>
string(0) ""
[26]=>
string(0) ""
}
[8]=>
array(27) {
[0]=>
string(10) "2017-05-11"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(5) "17001"
[4]=>
string(2) "50"
[5]=>
string(8) "0.002941"
[6]=>
string(8) "0.764775"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.764775"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.529592"
[14]=>
string(8) "3.059288"
[15]=>
string(9) "52.010956"
[16]=>
string(8) "1.040219"
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(0) ""
[21]=>
string(0) ""
[22]=>
string(0) ""
[23]=>
string(0) ""
[24]=>
string(0) ""
[25]=>
string(0) ""
[26]=>
string(0) ""
}
[9]=>
array(27) {
[0]=>
string(10) "2017-05-12"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(5) "16814"
[4]=>
string(2) "44"
[5]=>
string(8) "0.002617"
[6]=>
string(8) "0.773364"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.773364"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.546763"
[14]=>
string(8) "3.093651"
[15]=>
string(9) "52.016652"
[16]=>
string(8) "1.182197"
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(0) ""
[21]=>
string(0) ""
[22]=>
string(0) ""
[23]=>
string(0) ""
[24]=>
string(0) ""
[25]=>
string(0) ""
[26]=>
string(0) ""
}
[10]=>
array(27) {
[0]=>
string(10) "2017-05-13"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(5) "16880"
[4]=>
string(2) "32"
[5]=>
string(8) "0.001896"
[6]=>
string(8) "0.770245"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.770245"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.540520"
[14]=>
string(8) "3.081195"
[15]=>
string(9) "52.010570"
[16]=>
string(8) "1.625330"
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(0) ""
[21]=>
string(0) ""
[22]=>
string(0) ""
[23]=>
string(0) ""
[24]=>
string(0) ""
[25]=>
string(0) ""
[26]=>
string(0) ""
}
[11]=>
array(27) {
[0]=>
string(10) "2017-05-14"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(5) "17045"
[4]=>
string(2) "32"
[5]=>
string(8) "0.001877"
[6]=>
string(8) "0.762742"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.762742"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.525543"
[14]=>
string(8) "3.051212"
[15]=>
string(9) "52.007907"
[16]=>
string(8) "1.625247"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "1"
[25]=>
string(7) "52.0079"
[26]=>
string(4) "1.00"
}
[12]=>
array(27) {
[0]=>
string(10) "2017-05-15"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(4) "7294"
[4]=>
string(2) "10"
[5]=>
string(8) "0.001371"
[6]=>
string(8) "0.781126"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.781126"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.562252"
[14]=>
string(8) "3.124683"
[15]=>
string(9) "22.791441"
[16]=>
string(8) "2.279144"
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(0) ""
[21]=>
string(0) ""
[22]=>
string(0) ""
[23]=>
string(0) ""
[24]=>
string(0) ""
[25]=>
string(0) ""
[26]=>
string(0) ""
}
[13]=>
array(27) {
[0]=>
string(10) "2017-06-03"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "30186"
[4]=>
string(2) "42"
[5]=>
string(8) "0.001391"
[6]=>
string(8) "0.690422"
[7]=>
string(8) "0.690422"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.380910"
[14]=>
string(8) "2.761773"
[15]=>
string(9) "83.366884"
[16]=>
string(8) "1.984926"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "1"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "1"
[25]=>
string(7) "41.6834"
[26]=>
string(4) "2.00"
}
[14]=>
array(27) {
[0]=>
string(10) "2017-06-04"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "29952"
[4]=>
string(2) "25"
[5]=>
string(8) "0.000835"
[6]=>
string(8) "0.695962"
[7]=>
string(8) "0.695962"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.391983"
[14]=>
string(8) "2.783917"
[15]=>
string(9) "83.383894"
[16]=>
string(8) "3.335356"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(2) "12"
[25]=>
string(6) "6.9487"
[26]=>
string(5) "12.00"
}
[15]=>
array(27) {
[0]=>
string(10) "2017-06-05"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "29863"
[4]=>
string(2) "39"
[5]=>
string(8) "0.001306"
[6]=>
string(8) "0.697854"
[7]=>
string(8) "0.697854"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.395772"
[14]=>
string(8) "2.791494"
[15]=>
string(9) "83.362371"
[16]=>
string(8) "2.137497"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "4"
[21]=>
string(1) "2"
[22]=>
string(1) "1"
[23]=>
string(1) "0"
[24]=>
string(2) "15"
[25]=>
string(6) "3.7892"
[26]=>
string(5) "22.00"
}
[16]=>
array(27) {
[0]=>
string(10) "2017-06-06"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "29859"
[4]=>
string(2) "40"
[5]=>
string(8) "0.001340"
[6]=>
string(8) "0.698055"
[7]=>
string(8) "0.698055"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.396160"
[14]=>
string(8) "2.792283"
[15]=>
string(9) "83.374777"
[16]=>
string(8) "2.084369"
[17]=>
string(1) "0"
[18]=>
string(1) "1"
[19]=>
string(1) "0"
[20]=>
string(1) "4"
[21]=>
string(1) "2"
[22]=>
string(1) "1"
[23]=>
string(1) "0"
[24]=>
string(2) "21"
[25]=>
string(6) "2.8750"
[26]=>
string(5) "29.00"
}
[17]=>
array(27) {
[0]=>
string(10) "2017-06-07"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "29968"
[4]=>
string(2) "22"
[5]=>
string(8) "0.000734"
[6]=>
string(8) "0.695653"
[7]=>
string(8) "0.695653"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.391359"
[14]=>
string(8) "2.782683"
[15]=>
string(9) "83.391458"
[16]=>
string(8) "3.790521"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "1"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(2) "25"
[25]=>
string(6) "3.2074"
[26]=>
string(5) "26.00"
}
[18]=>
array(27) {
[0]=>
string(10) "2017-06-08"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "29967"
[4]=>
string(2) "41"
[5]=>
string(8) "0.001368"
[6]=>
string(8) "0.695284"
[7]=>
string(8) "0.695284"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.390634"
[14]=>
string(8) "2.781195"
[15]=>
string(9) "83.344075"
[16]=>
string(8) "2.032782"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "2"
[21]=>
string(1) "1"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(2) "23"
[25]=>
string(6) "3.2055"
[26]=>
string(5) "26.00"
}
[19]=>
array(27) {
[0]=>
string(10) "2017-06-09"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "14689"
[4]=>
string(1) "8"
[5]=>
string(8) "0.000545"
[6]=>
string(8) "0.686755"
[7]=>
string(8) "0.686755"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.373565"
[14]=>
string(8) "2.747041"
[15]=>
string(9) "40.351291"
[16]=>
string(8) "5.043911"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "2"
[23]=>
string(1) "0"
[24]=>
string(2) "21"
[25]=>
string(6) "1.7544"
[26]=>
string(5) "23.00"
}
[20]=>
array(27) {
[0]=>
string(0) ""
[1]=>
string(0) ""
[2]=>
string(0) ""
[3]=>
string(6) "286395"
[4]=>
string(3) "426"
[5]=>
string(8) "0.001487"
[6]=>
string(8) "0.718754"
[7]=>
string(8) "0.471867"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.246886"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.437560"
[14]=>
string(8) "2.875126"
[15]=>
string(10) "823.421824"
[16]=>
string(8) "1.932915"
[17]=>
string(1) "0"
[18]=>
string(1) "1"
[19]=>
string(1) "0"
[20]=>
string(2) "12"
[21]=>
string(1) "5"
[22]=>
string(1) "4"
[23]=>
string(1) "0"
[24]=>
string(3) "129"
[25]=>
string(6) "5.4531"
[26]=>
string(6) "151.00"
}
[21]=>
array(1) {
[0]=>
NULL
}
}
Use array_combine and extend your code to:
$data = array_map("str_getcsv", preg_split('/\r*\n+|\r+/', $result));
$new_data = [];
// shift first element of $data, we will use it as keys.
$keys = array_shift($data);
foreach ($data as $item) {
// create key => value array
$new_data[] = array_combine($keys, $item);
}
Thanks to #Kazz - in case of warnings like
array_combine(): Both parameters should have an equal number of elements
you need to check if both elements are arrays and theirs sizes equals (with count(), for example).