# SessionIterator

> SessionIterator implements an iterator (https://www.php.net/manual/en/class.iterator.php) for traversing session variables managed by yii\web\Session.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [web](/docs/api/yii/web/index.md) › SessionIterator

| class | `yii\web\SessionIterator` |
| --- | --- |
| Implements | [`Iterator`](https://www.php.net/manual/en/class.iterator.php) |
| Since | 2.0 |
| Source | [`framework/web/SessionIterator.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/web/SessionIterator.php#L19) |

SessionIterator implements an [iterator](https://www.php.net/manual/en/class.iterator.php) for traversing session variables managed by [`Session`](/docs/api/yii/web/session/index.md).

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Constructor. | `SessionIterator` |
| [`current()`](#method-current) | Returns the current array element. | `SessionIterator` |
| [`key()`](#method-key) | Returns the key of the current array element. | `SessionIterator` |
| [`next()`](#method-next) | Moves the internal pointer to the next array element. | `SessionIterator` |
| [`rewind()`](#method-rewind) | Rewinds internal array pointer. | `SessionIterator` |
| [`valid()`](#method-valid) | Returns whether there is an element at current position. | `SessionIterator` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct()
```

Constructor.

### current() <span id="method-current"></span>

```php
public function current(): mixed
```

Returns the current array element.

This method is required by the interface [`Iterator`](https://www.php.net/manual/en/class.iterator.php).

**Returns**

`mixed`: The current array element

### key() <span id="method-key"></span>

```php
public function key(): string|int|null
```

Returns the key of the current array element.

This method is required by the interface [`Iterator`](https://www.php.net/manual/en/class.iterator.php).

**Returns**

`string|int|null`: The key of the current array element

### next() <span id="method-next"></span>

```php
public function next(): mixed
```

Moves the internal pointer to the next array element.

This method is required by the interface [`Iterator`](https://www.php.net/manual/en/class.iterator.php).

**Returns**

`mixed`

### rewind() <span id="method-rewind"></span>

```php
public function rewind(): mixed
```

Rewinds internal array pointer.

This method is required by the interface [`Iterator`](https://www.php.net/manual/en/class.iterator.php).

**Returns**

`mixed`

### valid() <span id="method-valid"></span>

```php
public function valid(): bool
```

Returns whether there is an element at current position.

This method is required by the interface [`Iterator`](https://www.php.net/manual/en/class.iterator.php).

**Returns**

`bool`