Anemone::offsetSet()

Sets a value to the specified key/index in the data.

Table of Contents
  1. Description
  2. Example

Description

Anemone::offsetSet(mixed $key, mixed $value): void;

This method is a requirement to be able to implement the ArrayAccess interface and aims to make the object data modifiable using array access syntax. You won’t use this method directly, it will be executed automatically when you try to set an item with array access syntax. This method sets a value to the specified key/index in the data. If the key/index already exists in the data, then this method will override the value at that position.

Example

$anemone = new Anemone([1, 2, 3, 4, 5]);

$anemone[0] = '#';
$anemone[5] = 6;
$anemone[] = '#';
$anemone[] = '#';

test($anemone->get()); // Returns `['#', 2, 3, 4, 5, 6, '#', '#']`

You call the Anemone::get() method to return raw array values, but you can also directly iterate over it.

Anemone::any()

Checks if at least one item in the data passes the test.

Anemone::is()

Filters the data so that only items that pass the test are left.

Anemone::not()

Filters the data so that only items that do not pass the test are left.

Anemone::offsetSet()

Sets a value to the specified key/index in the data.

Anemone::pluck()

Returns a new data set contains values from the key on every item.