Такой ещё вариант!
function nextKey(array $array, $cookieKey){
$myKey = isset($_COOKIE[$cookieKey]) ? abs($_COOKIE[$cookieKey]) : 0;
$nextKey = isset($array[$myKey]) && isset($array[$myKey + 1]) ? $myKey + 1 : 0;
setcookie($cookieKey, $nextKey, time() + 86400);
return $array[$nextKey];
}
$files = [
'data/file1.txt',
'data/file2.txt',
];
$path = nextKey($files, 'slider');
$items = unserialize(file_get_contents($path));
foreach ($items as $item){
if (is_string($item) && mb_strlen($item) < 2){
continue;
}
$label = str_replace('-', ' ', $item);
echo '<li><b><a href="/' . $item . '/">' . $label . '</a></b></li>';
}