Anemone::chunk()

Splits the data into chunks.

Table of Contents
  1. Description
  2. Example

Description

Anemone::chunk(int $chunk = 5, int $part = -1, bool $keys = false): Anemone;

Splits the data into chunks. Optionally, returns the data chunk at the specified chunk index. This method returns new Anemone instance.

Example

$anemone = new Anemone(range(1, 20));

test($anemone->get()); // Returns `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]`
test($anemone->chunk(5)->get()); // Returns `[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]`
test($anemone->chunk(5, -1, true)->get()); // Returns `[[0 => 1, 1 => 2, 2 => 3, 3 => 4, 4 => 5], [5 => 6, 6 => 7, 7 => 8, 8 => 9, 9 => 10], [10 => 11, 11 => 12, 12 => 13, 13 => 14, 14 => 15], [15 => 16, 16 => 17, 17 => 18, 18 => 19, 19 => 20]]`
test($anemone->chunk(5, 2)->get()); // Returns `[11, 12, 13, 14, 15]`
test($anemone->chunk(5, 2, true)->get()); // Returns `[10 => 11, 11 => 12, 12 => 13, 13 => 14, 14 => 15]`

You call the Anemone::get() method to return raw array values, but you can also directly iterate over the values returned by this Anemone::chunk() method:

foreach ($anemone->chunk(5, 2) as $k => $v) {
    echo $k . ': ' . $v . '<br>';
}

Anemone::any()

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

Anemone::chunk()

Splits the data into chunks.

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::pluck()

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