我有一個超過100,000行的非常大的文本文件。我需要收集/跳過設定數量的線路:循環線路1-100,跳過線路101-150,讀取線路151-210,跳過線路211-300(例如)。PHP循環 - 跳過某些行
我有以下代碼
$lines = file('file.txt');
$counter = 0;
foreach ($lines as $lineNumber => $line) {
$counter++;
if ($counter < 101) {
//Do update stuff
}
if ($counter < 102 && $counter > 151) {
//Skip these lines
}
if ($counter < 152 && $counter > 211) {
//Do update stuff
}
}
有沒有更好的方式來跳過一個陣列輸出的多行?
不是一個好主意,在內存中有一個大文件 –
不要在這種情況下使用foreach,使用和利用計數器 – clearshot66
用'fread'逐行讀取文件 –