Is it possible to implement the loop value of the array, but only one value is used for each operation?

Source: Internet
Author: User
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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.