$list = new ArrayIterator(array('page1', 'page2', 'page3', 'page4'));
echo $list->current(); // 'page1'
$list->next();
echo $list->current(); // 'page2'
// What I want to achieve
$list->previous();
echo $list->current(); // 'page1'
From there, how can I get last element page1
?
2
Answers
You can use
seek()
method and key index to move internal pointer to last elementFull example
I had this problem with an associative ArrayIterator, and this works both for simple and associative arrays, if you track the numeric position of the pointer as you cycle through the array …
That outputs: