Anemone::chunk()
Splits the data into chunks.
Table of Contents
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::_()
The dynamic method initiator.
Anemone::__call()
Proxy for missing methods.
Anemone::__callStatic()
Proxy for missing static methods.
Anemone::__construct()
The constructor.
Anemone::__destruct()
The desctructor.
Anemone::__get()
Proxy for missing properties.
Anemone::__invoke()
Proxy for the current object, called as a function.
Anemone::__serialize()
Provides data to be serialized.
Anemone::__toString()
Proxy for the current object, casted as a string.
Anemone::__unserialize()
Converts the serialized data back to its object.
Anemone::all()
Checks if all items in the data pass the test.
Anemone::any()
Checks if at least one item in the data passes the test.
Anemone::chunk()
Splits the data into chunks.
Anemone::count()
Counts the amount of data.
Anemone::find()
Returns the first item in the data that passes the test.
Anemone::first()
Returns the first item in the data.
Anemone::from()
Object instantiator.
Anemone::get()
Gets value recursively.
Anemone::getIterator()
The external iterator receiver.
Anemone::has()
Checks for the existence of a key recursively.
Anemone::index()
Gets item position index in the data by key.
Anemone::is()
Filters the data so that only items that pass the test are left.
Anemone::join()
Joins the data into a string.
Anemone::jsonSerialize()
Returns the data to be serialized as JSON.
Anemone::key()
Gets item key in data by position index.
Anemone::last()
Returns the last item in the data.
Anemone::let()
Deletes value recursively.
Anemone::map()
Creates a new data set from the current data.
Anemone::mitose()
Creates a new instance without reference it to a variable.
Anemone::not()
Filters the data so that only items that do not pass the test are left.
Anemone::offsetExists()
Checks if an item with a certain key/index exists in the data.
Anemone::offsetGet()
Gets an item in the data using its key/index.
Anemone::offsetSet()
Sets a value to the specified key/index in the data.
Anemone::offsetUnset()
Deletes an item at the specified key/index in the data.
Anemone::pluck()
Returns a new data set contains values from the key on every item.
Anemone::reverse()
Reverses the order of the data.
Anemone::set()
Sets value recursively.
Anemone::shake()
Shakes the order of the data.
Anemone::sort()
Sorts the data.