我是
使用fgetcsv
读取csv文件while (($data = (empty($this -> enclosure)) ? $method($fp, 10000, $this -> delimiter) : $method($fp, 10000, $this -> delimiter, $this -> enclosure)) !== FALSE)
将每一行推送到数组
foreach($data as $l => $cont)
{
$this -> line[$i][$this -> fieldlist[$l]] = $cont;
}
(而fieldlist是一个包含标题字段的数组)
使用标题行和array_filter
查询此数组public function csv_query($search_for = array())
{
$this -> timeset("start csv query");
$return = array_filter($this -> line, function($var) use ($search_for){
$trigger = 0;
foreach($search_for as $index => $value)
{
if($var[$index] == $value)
{
$trigger+=1;
}
}
return ($trigger == count($search_for)) ? true : false;
});
$this -> timeset("finished csv query");
return $return;
}
到目前为止,这么好......有谁知道如何调整这种方法?
当然迭代大数组和fgetcsv需要时间。但这里有一些测量
1398418289.468287 - 0.000000 - initializing
1398418289.468335 - 0.000048 - finished constructor
1398418289.468410 - 0.000075 - file handler initialized
1398418291.186548 - 1.718138 - finished fgetcsv
1398418291.186563 - 0.000015 - start csv query
1398418291.302163 - 0.115600 - finished csv query
'查询数组'是:
$ q = array( 'VERFUEGBARKEIT'=> 'JA', 'HERSTELLERNUMMER'=> '906115301009' )