Home  >  Article  >  Backend Development  >  数组的循环取值,但历次只去一个值,有可能实现吗

数组的循环取值,但历次只去一个值,有可能实现吗

WBOY
WBOYOriginal
2016-06-13 11:18:391037browse

数组的循环取值,但每次只去一个值,有可能实现吗
假设一个数组
$ar=array(1,2,3,4,5,6,7,8,9);

第一次响应取出1,第二次取出2,这可能实现吗?

直接在网页实现,代码越简洁越好,不在乎执行效率问题。


------解决方案--------------------
session_start();<br />$ar = array(1,2,3,4,5,6,7,8,9);<br />if(! isset($_SESSION['offs'])) $_SESSION['offs'] = 0;<br />echo $ar[$_SESSION['offs']];<br />$_SESSION['offs'] = ($_SESSION['offs'] + 1) % count($ar);<br />
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn