class ArrayObject implements IteratorAggregate, ArrayAccess, Serializable, Countable (View source)

This class allows objects to work as arrays.

Constants

STD_PROP_LIST

Properties of the object have their normal functionality when accessed as list (var_dump, foreach, etc.).

ARRAY_AS_PROPS

Entries can be accessed as properties (read and write).

Methods

__construct(TValue[]|object $array = [], int $flags = 0, ArrayIterator> $iteratorClass = "ArrayIterator")

Construct a new array object

bool
offsetExists(TKey $key)

Returns whether the requested index exists

mixed
offsetGet(TKey $key)

Returns the value at the specified index

void
offsetSet(TKey $key, TValue $value)

Sets the value at the specified index to newval

void
offsetUnset(TKey $key)

Unsets the value at the specified index

void
append(TValue $value)

Appends the value

array
getArrayCopy()

Creates a copy of the ArrayObject.

int
count()

Get the number of public properties in the ArrayObject When the ArrayObject is constructed from an array all properties are public.

int
getFlags()

Gets the behavior flags.

void
setFlags(int $flags)

Sets the behavior flags.

asort(int $flags = SORT_REGULAR)

Sort the entries by value

ksort(int $flags = SORT_REGULAR)

Sort the entries by key

uasort($callback)

Sort the entries with a user-defined comparison function and maintain key association

uksort($callback)

Sort the entries by keys using a user-defined comparison function

natsort()

Sort entries using a "natural order" algorithm

natcasesort()

Sort an array using a case insensitive "natural order" algorithm

void
unserialize(string $data)

Unserialize an ArrayObject

string|null
serialize()

Serialize an ArrayObject

array
__debugInfo()

No description

array
__serialize()

No description

void
__unserialize(array $data)

No description

getIterator()

Create a new iterator from an ArrayObject instance

array
exchangeArray(mixed $array)

Exchange the array for another one.

void
setIteratorClass(ArrayIterator> $iteratorClass)

Sets the iterator classname for the ArrayObject.

string
getIteratorClass()

Gets the iterator classname for the ArrayObject.

Details

__construct(TValue[]|object $array = [], int $flags = 0, ArrayIterator> $iteratorClass = "ArrayIterator")

Construct a new array object

Parameters

TValue[]|object $array

The input parameter accepts an array or an Object.

int $flags

Flags to control the behaviour of the ArrayObject object.

ArrayIterator> $iteratorClass

Specify the class that will be used for iteration of the ArrayObject object. ArrayIterator is the default class used.

bool offsetExists(TKey $key)

Returns whether the requested index exists

Parameters

TKey $key

The index being checked.

Return Value

bool

true on success or false on failure.

The return value will be casted to boolean if non-boolean was returned.

mixed offsetGet(TKey $key)

Returns the value at the specified index

Parameters

TKey $key

The index with the value.

Return Value

mixed

Can return all value types.

void offsetSet(TKey $key, TValue $value)

Sets the value at the specified index to newval

Parameters

TKey $key

The index being set.

TValue $value

The value to set.

Return Value

void

void offsetUnset(TKey $key)

Unsets the value at the specified index

Parameters

TKey $key

The index being unset.

Return Value

void

void append(TValue $value)

Appends the value

Parameters

TValue $value

The value being appended.

Return Value

void

array getArrayCopy()

Creates a copy of the ArrayObject.

Return Value

array

a copy of the array. When the ArrayObject refers to an object an array of the public properties of that object will be returned.

int count()

Get the number of public properties in the ArrayObject When the ArrayObject is constructed from an array all properties are public.

Return Value

int

The custom count as an integer.

The return value is cast to an integer.

int getFlags()

Gets the behavior flags.

Return Value

int

the behavior flags of the ArrayObject.

void setFlags(int $flags)

Sets the behavior flags.

Parameters

int $flags

The new ArrayObject behavior. It takes on either a bitmask, or named constants. Using named constants is strongly encouraged to ensure compatibility for future versions.

The available behavior flags are listed below. The actual meanings of these flags are described in the predefined constants.

ArrayObject behavior flags
value constant
1 ArrayObject::STD_PROP_LIST
2 ArrayObject::ARRAY_AS_PROPS

Return Value

void

asort(int $flags = SORT_REGULAR)

Sort the entries by value

Parameters

int $flags

ksort(int $flags = SORT_REGULAR)

Sort the entries by key

Parameters

int $flags

uasort($callback)

Sort the entries with a user-defined comparison function and maintain key association

Parameters

$callback

uksort($callback)

Sort the entries by keys using a user-defined comparison function

Parameters

$callback

natsort()

Sort entries using a "natural order" algorithm

natcasesort()

Sort an array using a case insensitive "natural order" algorithm

void unserialize(string $data)

Unserialize an ArrayObject

Parameters

string $data

The string representation of the object.

Return Value

void

string|null serialize()

Serialize an ArrayObject

Return Value

string|null

The string representation of the object or null

array __debugInfo()

Since: 7.4

No description

Return Value

array

array __serialize()

Since: 7.4

No description

Return Value

array

void __unserialize(array $data)

Since: 7.4

No description

Parameters

array $data

Return Value

void

Traversable getIterator()

Create a new iterator from an ArrayObject instance

Return Value

Traversable

An instance of an object implementing Iterator or Traversable

array exchangeArray(mixed $array)

Exchange the array for another one.

Parameters

mixed $array

The new array or object to exchange with the current array.

Return Value

array

the old array.

void setIteratorClass(ArrayIterator> $iteratorClass)

Sets the iterator classname for the ArrayObject.

Parameters

ArrayIterator> $iteratorClass

The classname of the array iterator to use when iterating over this object.

Return Value

void

string getIteratorClass()

Gets the iterator classname for the ArrayObject.

Return Value

string

the iterator class name that is used to iterate over this object.