Anemone::__invoke()

Proxy for the current object, called as a function.

Table of Contents
  1. Description
  2. Example

Description

Anemone::__invoke(string $join = ', ', bool $filter = true): string;
Anemone::__invoke(string $join = ', ', callable $filter): string;

This method will be called when an Anemone instance is called as a function. This method will convert the data into a string by ignoring data that cannot be converted into a string, and ignoring data that has a value of false or null, and data that has a key with prefix _.

Example

$anemone = new Anemone([
    'a' => 1,
    'b' => 2,
    'c' => 3,
    'd' => [1, 2, 3],
    'e' => false,
    'f' => null,
    'g' => new class {
        public function __toString() {
            return '###';
        }
    }
]);

$test = $anemone(', '); // Returns `'1, 2, 3, ###'`

You can also implement a filter to return the desired values:

$test = $anemone(', ', function ($key, $value) {
    return is_string($value) && !str_starts_with($key, '#');
});

Anemone::__invoke()

Proxy for the current object, called as a function.

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.