Skip to content
Snippets Groups Projects

Ptps function 6

Merged Адлан Шамавов requested to merge PTPS_Function_6 into main
2 files
+ 0
69
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 0
51
@@ -143,56 +143,5 @@ class Functions {
yield new DateTimeImmutable($day->format("Y-m-d"));
}
}
/**
* Вернет кол-во дней между датами
* @param DateTimeImmutable $dateStart дата начала
* @param DateTimeImmutable $dateEnd дата окончания
* @return int
*/
function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int {
$dateInterval = date_diff($dateStart, $dateEnd);
return $dateInterval->format("%a") ;
}
/**
* Переделай своё решение 8 задачи:
* замени вывод всего текста из файла разом на
* построчный вывод используя yield
* @param string $filePath путь до файла
* @return void
*/
function readLogFile(string $filePath): void {
if (file_exists($filePath)) {
$text = "";
$file = fopen($filePath, "r");
while(!feof($file)) {
$line = fgets($file);
$text .= $line;
}
fclose($file);
print($text);
}
else print("Такого файла не существует.");
}
/**
* Переделай своё решение 8 задачи:
* замени вывод всего текста из файла разом на
* построчный вывод используя yield
* @param string $filePath путь до файла
* @return void
*/
function readFileLineByLine(string $filePath): iterable {
if (file_exists($filePath)) {
$file = fopen($filePath, "r");
while(!feof($file)) {
yield fgets($file);
}
fclose($file);
}
else yield "Такого файла не существует.";
}
}
Loading