( ):
, 5 , . 0 4:
for ($i = 0; $i < 5; $i++) { ...
. , 1 5:
for ($i = 0, $j = 1; $i < 5; $i++, $j++) { ...
^^^^^^ ^^^^
$i - , $j , .
, , , .
, $j 5, , reset 1. modulo. , $j , 5. modulo, % PHP:
for ($i = 0, $j = 3; $i < 5; $i++, $j %= 5, $j++) { ...
^^^^^^^
for, .
In this example, you can replace 3with your random starting number. Make sure that it is greater than 0 and lower than 6, otherwise at least the first iteration will give you the wrong number.
As you can imagine, there are several ways to do this, so this is just one example.
hakre source
share