Iterate in reverse through an array with PHP - SPL solution?
Is there an SPL Reverse array iterator in PHP? And if not, what would be the best way to achieve it? I could simply do $array = array_reverse($array); foreach($array as $currentElement) {} or for($i = count($array) - 1; $i >= 0; $i--) { } But is there a more elegant way? There is no ReverseArrayIterator to do that. You can do $reverted = new ArrayIterator(array_reverse($data)); or make that into your own custom iterator, e.g. class ReverseArrayIterator extends ArrayIterator { public function __construct(array $array) { parent::__construct(array_reverse($array)); } } linepogl Here is a solution