ArrayStack.php 855 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace Zend\Stdlib;
  10. use ArrayIterator;
  11. use ArrayObject as PhpArrayObject;
  12. /**
  13. * ArrayObject that acts as a stack with regards to iteration
  14. */
  15. class ArrayStack extends PhpArrayObject
  16. {
  17. /**
  18. * Retrieve iterator
  19. *
  20. * Retrieve an array copy of the object, reverse its order, and return an
  21. * ArrayIterator with that reversed array.
  22. *
  23. * @return ArrayIterator
  24. */
  25. public function getIterator()
  26. {
  27. $array = $this->getArrayCopy();
  28. return new ArrayIterator(array_reverse($array));
  29. }
  30. }