I could not identify any patterns in the sequence that would make it easier to create. The closest I got was doing:
foreach (range(0, 23) as $i)
echo ($i*8 + 1) % 23, ' ';
But the output is:
1 9 17 2 10 18 3 11 19 4 12 20 5 13 21 6 14 22 7 15 0 8 16 1
Obviously failing when the output value should be 23 or 24, since the general term used will never return a value greater than 22, that is, it worked for 91.67% of the sequence.
However, taking advantage of your logic, if you need to iterate over these values, you should define a generator:
function sequencia() {
foreach (range(1, 8) as $i) {
yield $i;
yield $i + 8;
yield $i + 16;
}
}
In this way you can take advantage of the returned values - rather than just printed on the screen:
foreach(sequencia() as $i)
echo $i, ' ';
Generating:
1 9 17 2 10 18 3 11 19 4 12 20 5 13 21 6 14 22 7 15 23 8 16 24
If you like a more functional footprint:
function sequencia()
{
return array_reduce(
array_map(
function ($x, $y, $z) {
return [$x, $y, $z];
},
...array_chunk(range(1, 24), 8)
),
"array_merge",
[]
);
}
The result will be exactly the sequence you want, but in my view, it's adding complexity with no motives. As Maniero said, elegance is relative.