以批处理方式处理php中的批量csv

以批处理方式处理php中的批量csv,php,csv,Php,Csv,我有一个超过34000行的csv文件。如何将此csv作为批处理(执行某些操作)。我的意思是,我必须先处理前100行,然后再处理下100行,以此类推,在单个函数调用中将其加载到数组中,然后以100为一批进行处理(更新): $myArray=getCSV(“filename.csv”); $allRows=$myArray.count(); 而($allRows>0){ 对于($x=0;$x

我有一个超过34000行的csv文件。如何将此csv作为批处理(执行某些操作)。我的意思是,我必须先处理前100行,然后再处理下100行,以此类推,在单个函数调用中将其加载到数组中,然后以100为一批进行处理(更新):

$myArray=getCSV(“filename.csv”);
$allRows=$myArray.count();
而($allRows>0){
对于($x=0;$x<100;$x++){
{在这里执行代码}
$allRows--;
if($allRows==0)$x=100;//脱离for循环
}
}
....
函数getCSV($file){
ini_set('memory_limit','1024M');//如果文件太大,则设置为高
$arrResult=array();
$arrFile=文件($file);
$foreach($arrfileas$line){
$arrResult[]=分解(“,”,$line);
}
返回$arresult;
}

循环和计数器。祝你好运。。。
$myArray = getCSV("filename.csv");
$allRows = $myArray.count();
while ($allRows > 0) {
    for ($x = 0; $x < 100; $x++) {
        { do your code here }
        $allRows--;
        if ($allRows == 0) $x = 100; // fall out of for loop
    }
}

....

function getCSV($file) {
    ini_set('memory_limit', '1024M'); // set high in case file is really big
    $arrResult = array();
    $arrFile = file($file);
    $foreach($arrFile as $line) {
        $arrResult[] = explode(',', $line);
    }
    return $arrResult;
}