PHP Basics

IteratorTrait

A generic implementation of the Iterator interface.

Tags
author

Sebastian Meyer sebastian.meyer@opencultureconsulting.com

template

TKey of int|string

template

TValue of mixed

template

TData of array<TKey, TValue>

Table of Contents

Properties

$data  : TData
Holds the iterable data.

Methods

current()  : TValue|false
Return the current item.
key()  : TKey|null
Return the current key.
next()  : void
Move forward to next item.
prev()  : void
Move back to previous item.
rewind()  : void
Rewind the iterator to the first item.
valid()  : bool
Check if current position is valid.

Properties

Methods

current()

Return the current item.

public current() : TValue|false
APIYes
Return values
TValue|false

The current item or FALSE if invalid

key()

Return the current key.

public key() : TKey|null
APIYes
Return values
TKey|null

The current key or NULL if invalid

next()

Move forward to next item.

public next() : void
APIYes

prev()

Move back to previous item.

public prev() : void
APIYes

rewind()

Rewind the iterator to the first item.

public rewind() : void
APIYes

valid()

Check if current position is valid.

public valid() : bool
APIYes
Return values
bool

Whether the current position is valid


        
On this page

Search results