Collection
class Collection implements Countable, Iterator
Collection, an util to conventionally store a key-value pair.
Properties
protected array | $data |
Methods
I think you are supposed to know what this does.
No description
Returns the current element.
Fetch the key from the current element.
Advances the internal pointer.
Resets the internal pointer.
Checks if current position is valid.
Removes an item from the collection by its key.
Clears the Collection.
Breaks the collection into multiple, smaller chunks of a given size. Returns a new Collection.
Returns the total number of items in the collection.
Returns a copy of itself.
Compares the collection against another collection or a plain PHP array based on its value. Returns a new Collection.
Returns all items.
Compares the collection against another collection or a plain PHP array based on its key. Returns a new Collection.
Iterates over the items in the collection and passes each item to a given callback. Returning false
in the callback will stop the processing.
Returns true if all elements pass the given truth test.
Returns all items in the collection except for those with the specified keys. Returns a new Collection.
Returns the first element in the collection that passes a given truth test.
Flattens a multi-dimensional collection into a single dimension. Returns a new Collection.
No description
Returns the item for a given key. If the key does not exist, null is returned.
Groups the collection's items by a given key. Returns a new Collection.
Determines if a given key exists in the collection.
Joins the items in a collection. Its arguments depend on the type of items in the collection.
Returns the position of the given value in the collection. Returns null if the given value couldn't be found.
Removes any values that are not present in the given array or collection. Returns a new Collection.
Returns all of the collection's keys. Returns a new Collection.
Returns the last element in the collection that passes a given truth test.
Iterates through the collection and passes each value to the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items.
Return the maximum value of a given key.
Return the minimum value of a given key.
Merges the given collection into this collection, resulting in a new collection.
Creates a new collection consisting of every n-th element.
Returns the items in the collection with the specified keys. Returns a new Collection.
Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.
Sets a key-value pair.
Return the values from a single column in the input array. Returns a new Collection.
Returns one random item, or multiple random items inside a Collection, from the Collection. Returns a new Collection.
Reduces the collection to a single value, passing the result of each iteration into the subsequent iteration.
Reverses the order of the collection's items. Returns a new Collection.
Searches the collection for the given value and returns its key if found. If the item is not found, false is returned.
Randomly shuffles the items in the collection. Returns a new Collection.
Returns a slice of the collection starting at the given index. Returns a new Collection.
Returns true if at least one element passes the given truth test.
Sorts the collection, using sort behaviour flags. Returns a new Collection.
Sorts the collection by key, using sort behaviour flags. Returns a new Collection.
Sorts the collection using a custom sorting function. Returns a new Collection.
Sorts the collection by key using a custom sorting function. Returns a new Collection.
Returns all of the unique items in the collection. Returns a new Collection.
Filters the collection by a given callback, keeping only those items that pass a given truth test. Returns a new Collection.
Returns a new collection with the keys reset to consecutive integers.
Details
at line 26
__construct(array $data = null)
I think you are supposed to know what this does.
at line 37
mixed
__debugInfo()
at line 47
mixed
current()
Returns the current element.
at line 57
mixed
key()
Fetch the key from the current element.
at line 67
void
next()
Advances the internal pointer.
at line 77
void
rewind()
Resets the internal pointer.
at line 87
bool
valid()
Checks if current position is valid.
at line 97
$this
delete(mixed $key)
Removes an item from the collection by its key.
at line 108
$this
clear()
Clears the Collection.
at line 120
Collection
chunk(int $numitems, bool $preserve_keys = false)
Breaks the collection into multiple, smaller chunks of a given size. Returns a new Collection.
at line 129
int
count()
Returns the total number of items in the collection.
at line 138
Collection
copy()
Returns a copy of itself.
at line 148
Collection
diff(mixed[]|Collection $arr)
Compares the collection against another collection or a plain PHP array based on its value. Returns a new Collection.
at line 161
mixed[]
all()
Returns all items.
at line 171
Collection
diffKeys(mixed[]|Collection $arr)
Compares the collection against another collection or a plain PHP array based on its key. Returns a new Collection.
at line 185
$this
each(callable $closure)
Iterates over the items in the collection and passes each item to a given callback. Returning false
in the callback will stop the processing.
at line 202
bool
every(callable $closure)
Returns true if all elements pass the given truth test.
at line 218
Collection
except(array $keys)
Returns all items in the collection except for those with the specified keys. Returns a new Collection.
at line 235
mixed|null
first(callable $closure = null)
Returns the first element in the collection that passes a given truth test.
at line 261
Collection
flatten(int $depth = 0)
Flattens a multi-dimensional collection into a single dimension. Returns a new Collection.
at line 274
protected array
flattenDo(array $array, int $depth, int $inDepth = 0)
at line 295
mixed|null
get(mixed $key)
Returns the item for a given key. If the key does not exist, null is returned.
at line 305
Collection
groupBy(callable|mixed $column)
Groups the collection's items by a given key. Returns a new Collection.
at line 332
bool
has(mixed $key)
Determines if a given key exists in the collection.
at line 345
string
implode(mixed $col, string $glue = ', ')
Joins the items in a collection. Its arguments depend on the type of items in the collection.
If the collection contains arrays or objects, you should pass the key of the attributes you wish to join, and the "glue" string you wish to place between the values.
at line 375
int|null
indexOf(mixed $value)
Returns the position of the given value in the collection. Returns null if the given value couldn't be found.
at line 395
Collection
intersect(mixed[]|Collection $arr)
Removes any values that are not present in the given array or collection. Returns a new Collection.
at line 408
Collection
keys()
Returns all of the collection's keys. Returns a new Collection.
at line 418
mixed|null
last(callable $closure = null)
Returns the last element in the collection that passes a given truth test.
at line 445
Collection
map(callable $closure)
Iterates through the collection and passes each value to the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items.
at line 458
int
max(mixed|null $key = null)
Return the maximum value of a given key.
at line 474
int
min(mixed|null $key = null)
Return the minimum value of a given key.
at line 491
Collection
merge(Collection $collection)
Merges the given collection into this collection, resulting in a new collection.
Any string key in the given collection matching a string key in this collection will overwrite the value in this collection.
at line 503
Collection
nth(int $nth, int $offset = 0)
Creates a new collection consisting of every n-th element.
at line 524
Collection
only(array $keys)
Returns the items in the collection with the specified keys. Returns a new Collection.
at line 541
Collection[]
partition(callable $closure)
Partitions the collection into two collections where the first collection contains the items that passed and the second contains the items that failed.
at line 563
$this
set(mixed $key, mixed $value)
Sets a key-value pair.
at line 575
Collection
pluck(mixed $key, mixed $index = null)
Return the values from a single column in the input array. Returns a new Collection.
at line 607
Collection
random(int $num = 1)
Returns one random item, or multiple random items inside a Collection, from the Collection. Returns a new Collection.
at line 628
mixed|null|void
reduce(callable $closure, mixed|null $carry = null)
Reduces the collection to a single value, passing the result of each iteration into the subsequent iteration.
at line 642
Collection
reverse(bool $preserve_keys = false)
Reverses the order of the collection's items. Returns a new Collection.
at line 653
mixed|bool
search(mixed $needle, bool $strict = true)
Searches the collection for the given value and returns its key if found. If the item is not found, false is returned.
at line 662
Collection
shuffle()
Randomly shuffles the items in the collection. Returns a new Collection.
at line 677
Collection
slice(int $offset, int $limit = null, bool $preserve_keys = false)
Returns a slice of the collection starting at the given index. Returns a new Collection.
at line 688
bool
some(callable $closure)
Returns true if at least one element passes the given truth test.
at line 705
Collection
sort(bool $descending = false, int $options = \SORT_REGULAR)
Sorts the collection, using sort behaviour flags. Returns a new Collection.
at line 724
Collection
sortKey(bool $descending = false, int $options = \SORT_REGULAR)
Sorts the collection by key, using sort behaviour flags. Returns a new Collection.
at line 742
Collection
sortCustom(callable $closure)
Sorts the collection using a custom sorting function. Returns a new Collection.
at line 755
Collection
sortCustomKey(callable $closure)
Sorts the collection by key using a custom sorting function. Returns a new Collection.
at line 770
Collection
unique(mixed|null $key, int $options = \SORT_REGULAR)
Returns all of the unique items in the collection. Returns a new Collection.
at line 808
Collection
filter(callable $closure)
Filters the collection by a given callback, keeping only those items that pass a given truth test. Returns a new Collection.
at line 825
Collection
values()
Returns a new collection with the keys reset to consecutive integers.