php8.5
Home/ Manual/ spl / arrayiterator/ ArrayIterator::__construct

ArrayIterator::__construct

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Construct an ArrayIterator

Description

ArrayIterator::__construct(array|object $array = [], int $flags = 0)

Constructs an ArrayIterator object.

Func

Parameters

array

The array or object to be iterated on. Passing an object is deprecated as of PHP 8.5.0.

flags

Flags to control the behaviour of the ArrayIterator object. See ArrayIterator::setFlags.

Errors/Exceptions

As of PHP 8.5.0, throws an InvalidArgumentException if array is an enum.

Changelog

VersionDescription
8.5.0Passing an enum as array now throws an InvalidArgumentException.
8.5.0Passing an object as array is deprecated.

See Also

  • ArrayIterator::getArrayCopy
  • ArrayIterator::setFlags
  • ArrayObject::__construct

Source: reference/spl/arrayiterator/construct.xml · from the official PHP manual (php/doc-en)