Anemone::sort()
Sorts the data.
Table of Contents
Description
Anemone::sort(array $order = [int $sort, string $by], bool $keys = false): self;
Anemone::sort(callable $fn, bool $keys = false): self;
Anemone::sort(int $sort = 1, bool $keys = false): self;
This method sorts the data based on the value of a column on every item in the data.
Example
$anemone = new Anemone([
'foo' => [
'size' => 'medium',
'color' => 'green',
'id' => 2
],
'bar' => [
'id' => 4
],
'baz' => [
'size' => 'large',
'color' => 'blue',
'id' => 3
],
'qux' => [
'size' => 'small',
'color' => 'red',
'id' => 1
]
]);
test($anemone->mitose()->sort(+1)->get()); // Sorts items ascending (does not work properly on associative array data)
test($anemone->mitose()->sort([+1, 'color'], true)->get()); // Sorts items ascending by `color` value
test($anemone->mitose()->sort(function ($a, $b) {
$a = $a['color'][1] ?? "";
$b = $b['color'][1] ?? "";
return $a <=> $b;
}, true)->get()); // Sorts items ascending by the second letter of `color` value
You call the Anemone::get()
method to return raw array values, but you can also directly iterate over it.
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.