ArrayStack.php 782 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. declare(strict_types=1);
  3. namespace Laminas\Stdlib;
  4. use ArrayIterator;
  5. use ArrayObject as PhpArrayObject;
  6. use ReturnTypeWillChange;
  7. use function array_reverse;
  8. /**
  9. * ArrayObject that acts as a stack with regards to iteration
  10. *
  11. * @template TKey of array-key
  12. * @template TValue
  13. * @template-extends PhpArrayObject<TKey, TValue>
  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<TKey, TValue>
  24. */
  25. #[ReturnTypeWillChange]
  26. public function getIterator()
  27. {
  28. $array = $this->getArrayCopy();
  29. return new ArrayIterator(array_reverse($array));
  30. }
  31. }