php - Looping exceed the array limit -
using php example , there array:
$list = array("a", "b", "c");
i nth element of array if infinite loop. example, 11th element here "b"
:
b c b c b c b c ... 1 2 3 4 5 6 7 8 9 10 11 12 ... ^
how loop on array this?
simply use %
modulus
<?php $list = array("a", "b", "c"); $position = 11; $index = $position % count($list) - 1; echo $list[$index];
demo : https://eval.in/847933
Comments
Post a Comment