Collection
class Collection implements ArrayAccess, Countable, IteratorAggregate
Collection.
Traits
Properties
static protected array | $_extensions | Class extensions. | from ExtendableTrait |
protected array | $items | Collection items. |
Methods
Executes class extensions.
Constructor.
Returns all the items in the collection.
Returns all the values in the collection.
Resets the collection keys.
Adds a new item to the collection.
Returns TRUE if the item key exists and FALSE if not.
Returns an item from the collection.
Removes an item from the collection.
Clears the collection.
Checks whether or not an offset exists.
Returns the value at the specified offset.
Assigns a value to the specified offset.
Unsets an offset.
Returns the numner of items in the collection.
Retruns an array iterator object.
Returns TRUE if the collection is empty and FALSE if not.
Prepends the passed item to the front of the collection and returns the new number of elements in the collection.
Shifts the first value of the collection off and returns it, shortening the collection by one element.
Pushes the passed variable onto the end of the collection and returns the new number of elements in the collection.
Pops and returns the last value of the collection, shortening the collection by one element.
Sorts the collection using the specified comparator callable and returns TRUE on success and FALSE on failure.
Chunks the collection into a collection containing $size sized collections.
Shuffles the items in the collection and returns TRUE on success and FALSE on failure.
Applies the callable on all items in the collection.
Returns a new collection where the callable has been applied to all the items.
Returns a new filtered collection.
Returns a new collection where all items not in the provided list have been removed.
Returns a new collection where all items in the provided list have been removed.
Details
in ExtendableTrait at line 35
static
addMethod(string $methodName, Closure $closure)
Adds a method to the class.
in ExtendableTrait at line 47
mixed
__call(string $name, array $arguments)
Executes class extensions.
in ExtendableTrait at line 64
static mixed
__callStatic(string $name, array $arguments)
Executes class extensions.
at line 59
__construct(array $items = [])
Constructor.
at line 69
array
getItems()
Returns all the items in the collection.
at line 79
array
getValues()
Returns all the values in the collection.
at line 89
$this
resetKeys()
Resets the collection keys.
at line 103
$this
put(int|string $key, mixed $value)
Adds a new item to the collection.
at line 116
bool
has(int|string $key)
Returns TRUE if the item key exists and FALSE if not.
at line 128
mixed
get(int|string $key, mixed $default = null)
Returns an item from the collection.
at line 144
$this
remove(int|string $key)
Removes an item from the collection.
at line 156
$this
clear()
Clears the collection.
at line 169
bool
offsetExists(mixed $offset)
Checks whether or not an offset exists.
at line 180
mixed
offsetGet(mixed $offset)
Returns the value at the specified offset.
at line 196
offsetSet(mixed $offset, mixed $value)
Assigns a value to the specified offset.
at line 213
offsetUnset(mixed $offset)
Unsets an offset.
at line 223
int
count()
Returns the numner of items in the collection.
at line 233
ArrayIterator
getIterator()
Retruns an array iterator object.
at line 243
bool
isEmpty()
Returns TRUE if the collection is empty and FALSE if not.
at line 255
int
unshift(mixed $item)
Prepends the passed item to the front of the collection and returns the new number of elements in the collection.
at line 266
mixed
shift()
Shifts the first value of the collection off and returns it, shortening the collection by one element.
at line 278
int
push(mixed $item)
Pushes the passed variable onto the end of the collection and returns the new number of elements in the collection.
at line 289
mixed
pop()
Pops and returns the last value of the collection, shortening the collection by one element.
at line 302
$this
sort(callable $comparator, bool $maintainIndexAssociation = true)
Sorts the collection using the specified comparator callable and returns TRUE on success and FALSE on failure.
at line 322
Collection
chunk(int $size)
Chunks the collection into a collection containing $size sized collections.
at line 340
$this
shuffle()
Shuffles the items in the collection and returns TRUE on success and FALSE on failure.
at line 353
$this
each(callable $callable)
Applies the callable on all items in the collection.
at line 370
Collection
map(callable $callable)
Returns a new collection where the callable has been applied to all the items.
at line 385
Collection
filter(callable|null $callable = null)
Returns a new filtered collection.
at line 401
Collection
with(array $keys)
Returns a new collection where all items not in the provided list have been removed.
at line 412
Collection
without(array $keys)
Returns a new collection where all items in the provided list have been removed.
at line 423
Collection
merge(Collection $collection)
Merges two collections.