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

WBOY
Release: 2016-06-13 11:18:39
Original
1035 people have browsed it

数组的循环取值,但每次只去一个值,有可能实现吗
假设一个数组
$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 />
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!