需要将CSV数据转换为密钥二维数组
------------ file = csvdata.csv --------
symbol,date1,date2,date3,date4
QCOM,10,11,12,13
CTSH,20,21,22,23
AAPL,41,42,43,44
------------ end of csv file ----
$inputsymbol = QCOM ; // $inputsymbol will come from html FORM.
注意:
匹配$ inputsymbol的数据应该包含在$ data1数组中,该数组需要如下所示。
$data1 = array (
array(date1,10),
array(date2,11),
array(date3,12),
array(date4,13)
);
答案 0 :(得分:1)
...解决
$filename1 = "sample.csv";
$fp1 = fopen("$filename1","r");
$header1 = fgetcsv($fp1);
$col1 = count($header1) - 1;
while (($data = fgetcsv($fp1)) !== FALSE)
{
if ($data[0] == $inputsymbol)
{
for ($rows = 0; $rows<$col1 ; $rows++)
{
$data1[$rows][0] = $header1[$rows+1];
$data1[$rows][1] = $data[$rows+1];
}
}
}