Array loop value, but only one value at a time, is it possible to implement? suppose an array $ ar = array (1, 2, 3, 4, 5, 6, 7, 8, 9); the first response to get 1, is it possible to retrieve 2 for the second time? Directly implemented on the webpage, the simpler the code, the better, and the less efficient the execution. Array loop value, but only one value is allowed at a time. Is it possible to achieve this?
Suppose an array
$ Ar = array (1, 2, 3, 4, 5, 6, 7, 8, 9 );
Is it possible to retrieve 1 in the first response and 2 in the second response?
Directly implemented on the webpage, the simpler the code, the better, and the less efficient the execution.
------ Solution --------------------
Session_start ();
$ Ar = array (1, 2, 3, 4, 5, 6, 7, 8, 9 );
If (! Isset ($ _ SESSION ['offs']) $ _ SESSION ['offs'] = 0;
Echo $ ar [$ _ SESSION ['offs'];
$ _ SESSION ['offs'] = ($ _ SESSION ['offs'] + 1) % count ($ ar );