If $lines is actually numerically indexed, then you should use:
$n = 8;
for ($i = $n - 1; $i < count($lines); $i += $n) {
// key = $i
// value = $lines[$i]
echo $lines[$i];
}
If you are dealing with an associative array, then you may have to resort to:
$keys = array_keys($lines);
$n = 8;
for ($i = $n - 1; $i < count($keys); $i += $n) {
// key = $keys[$i]
// value = $lines[$keys[$i]]
}
or:
$n = 8;
$i = 1;
foreach ($lines as $line_num => $line) {
if ($i % 8 == 0) {
echo $line;
}
++$i;
}
or if the key is not important:
$lines = array_values($lines);
$n = 8;
for ($i = $n - 1; $i < count($lines); $i += $n) {
// key = $i
// value = $lines[$i]
echo $lines[$i];
}