yii\base\ArrayAccessTrait - Yii2 类参考手册

Trait yii\base\ArrayAccessTrait

Implemented byyii\elasticsearch\ActiveFixture, yii\mongodb\ActiveFixture, yii\test\ActiveFixture, yii\test\ArrayFixture, yii\test\BaseActiveFixture
Available since version2.0

ArrayAccessTrait provides the implementation for IteratorAggregate, ArrayAccess and Countable.

Note that ArrayAccessTrait requires the class using it contain a property named data which should be an array. The data will be exposed by ArrayAccessTrait to support accessing the class object like an array.

Public Methods

隐藏继承的方法 Hide inherited methods

方法 Method简介 Description定义在 Defined By
count() Returns the number of data items. yii\base\ArrayAccessTrait
getIterator() Returns an iterator for traversing the data. yii\base\ArrayAccessTrait
offsetExists() This method is required by the interface ArrayAccess. yii\base\ArrayAccessTrait
offsetGet() This method is required by the interface ArrayAccess. yii\base\ArrayAccessTrait
offsetSet() This method is required by the interface ArrayAccess. yii\base\ArrayAccessTrait
offsetUnset() This method is required by the interface ArrayAccess. yii\base\ArrayAccessTrait

方法详情 Method Details

count() public method

Returns the number of data items.

This method is required by Countable interface.

public integer count ( )
return integer

Number of data elements.

getIterator() public method

Returns an iterator for traversing the data.

This method is required by the SPL interface IteratorAggregate. It will be implicitly called when you use foreach to traverse the collection.

public ArrayIterator getIterator ( )
return ArrayIterator

An iterator for traversing the cookies in the collection.

offsetExists() public method

This method is required by the interface ArrayAccess.

public boolean offsetExists ( $offset )
$offset mixed

The offset to check on

offsetGet() public method

This method is required by the interface ArrayAccess.

public mixed offsetGet ( $offset )
$offset integer

The offset to retrieve element.

return mixed

The element at the offset, null if no element is found at the offset

offsetSet() public method

This method is required by the interface ArrayAccess.

public void offsetSet ( $offset, $item )
$offset integer

The offset to set element

$item mixed

The element value

offsetUnset() public method

This method is required by the interface ArrayAccess.

public void offsetUnset ( $offset )
$offset mixed

The offset to unset element