Anemone::pluck()

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

Table of Contents
  1. Description
  2. Example

Description

Anemone::pluck(string $key, mixed $value = null, bool $keys = false): Anemone;

This is the OOP style of function pluck(), implemented as a class method. It returns a new data set contains values from the key on every item in the original data set. This method returns new Anemone instance.

Example

$anemone = new Anemone([
    ['id' => 1, 'value' => 'A'],
    ['id' => 2, 'value' => 'B'],
    ['id' => 3, 'value' => 'C'],
    ['id' => 4, 'value' => 'D'],
    ['id' => 5, 'value' => 'E'],
    ['id' => 6, 'value' => 'F'],
    ['id' => 7]
]);

test($anemone->pluck('value')->get()); // Returns `['A', 'B', 'C', 'D', 'E', 'F', null]`
test($anemone->pluck('value', '#')->get()); // Returns `['A', 'B', 'C', 'D', 'E', 'F', '#']`

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

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