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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -