Skip to content
Snippets Groups Projects

Ptps function 9

Merged Адлан Шамавов requested to merge PTPS_Function_9 into main
Files
2
+ 22
0
@@ -207,5 +207,27 @@ class Functions
throw new RuntimeException("File not found: $filePath");
}
}
/**
* Переделай своё решение 8 задачи:
* замени вывод всего текста из файла разом на
* построчный вывод используя yield
* @param string $filePath путь до файла
* @return iterable
*/
public function readFileLineByLine(string $filePath): iterable
{
if (file_exists($filePath)) {
$file = fopen($filePath, 'rb');
while(!feof($file)) {
yield fgets($file);
}
fclose($file);
}
else {
throw new RuntimeException("File not found: $filePath");
}
}
}
Loading