Я бы посоветовал перейти на файловый подход, чтобы отслеживать вещи. Это будет более надежный и переносимый подход из-за отсутствия зависимости от часовых поясов или летнего времени
Файловый подход
<?php
//read the last record
try
{
$fileName = "record.txt";
if ( !file_exists($fileName) ) {
file_put_contents("record.txt",'0'); // default - first line if run first time
}
$fp = fopen($fileName, "r+");
if ( !$fp ) {
throw new Exception('File open failed.');
}
$str = (int) fread($fp, 1); // read the first char, index to use for array
fclose($fp);
} catch ( Exception $e ) {
echo $e->getMessage();
}
$list = array
(
"some text|blue|22|sky",
"some text|red|42|ocean",
"some text|green|25|mountain",
"some text|orange|62|space",
"some text|brown|15|earth",
);
$file = fopen("output.csv","w");
$line = $list[$str];
fputcsv($file,explode('|',$line));
fclose($file);
//save what index should it read next time
$incr = intval($str)+1;
$incr = $incr == ( count($list) )? 0: $incr;
file_put_contents("record.txt",$incr);
Подход, основанный на дате
<?php
$date = new DateTime();
$week = $date->format("W");
$list = array
(
"some text|blue|22|sky",
"some text|red|42|ocean",
"some text|green|25|mountain",
"some text|orange|62|space",
"some text|brown|15|earth",
);
$str = $week % count($list);
$file = fopen("output.csv","w");
$line = $list[$str];
fputcsv($file,explode('|',$line));
fclose($file);
Одно из преимуществ подхода, основанного на дате, стоит отметить, если запуститьСценарий несколько раз в течение недели вы получите один и тот же вывод, но это не относится к файловому подходу, так как record.txt будет меняться при каждом запуске сценария.