I’m making a call to a PHP script that returns a random element from an array using array_rand(). It echos out some text that I’m ajaxing into another page. I’d like to have it echo out each successive element each time I load the page. So basically, I’m trying to figure out a way to echo out the first element when I load the page once, then the second element when I refresh, and so on. The thought maybe there would be a way to do it with array_pop(), but it removes each element, and I want to keep the array intact.
Share
I think
nextis what you’re looking for. It returns the next element in an array without removing it. However, if you must do that in between page refreshes, you’ll have to keep track of which element you’re at yourself, because the array pointers will be lost on page refresh. Using a $_SESSION variasble could do the trick.