MediaWiki REL1_34
ReverseArrayIterator.php
Go to the documentation of this file.
1<?php
29class ReverseArrayIterator implements Iterator, Countable {
31 protected $array;
32
41 public function __construct( $array = [] ) {
42 if ( is_array( $array ) ) {
43 $this->array = $array;
44 } elseif ( is_object( $array ) ) {
45 $this->array = get_object_vars( $array );
46 } else {
47 throw new InvalidArgumentException( __METHOD__ . ' requires an array or object' );
48 }
49
50 $this->rewind();
51 }
52
53 public function current() {
54 return current( $this->array );
55 }
56
57 public function key() {
58 return key( $this->array );
59 }
60
61 public function next() {
62 prev( $this->array );
63 }
64
65 public function rewind() {
66 end( $this->array );
67 }
68
69 public function valid() {
70 return key( $this->array ) !== null;
71 }
72
73 public function count() {
74 return count( $this->array );
75 }
76}
Convenience class for iterating over an array in reverse order.
__construct( $array=[])
Creates an iterator which will visit the keys in $array in reverse order.