class Collection implements ArrayAccess, Countable, IteratorAggregate

Collection.

Traits

Extendable trait.

Properties

static protected array $_extensions Class extensions. from ExtendableTrait
protected array $items Collection items.

Methods

static 
addMethod(string $methodName, Closure $closure)

Adds a method to the class.

mixed
__call(string $name, array $arguments)

Executes class extensions.

static mixed
__callStatic(string $name, array $arguments)

Executes class extensions.

__construct(array $items = [])

Constructor.

array
getItems()

Returns all the items in the collection.

array
getValues()

Returns all the values in the collection.

$this
resetKeys()

Resets the collection keys.

$this
put(int|string $key, mixed $value)

Adds a new item to the collection.

bool
has(int|string $key)

Returns TRUE if the item key exists and FALSE if not.

mixed
get(int|string $key, mixed $default = null)

Returns an item from the collection.

$this
remove(int|string $key)

Removes an item from the collection.

$this
clear()

Clears the collection.

bool
offsetExists(mixed $offset)

Checks whether or not an offset exists.

mixed
offsetGet(mixed $offset)

Returns the value at the specified offset.

offsetSet(mixed $offset, mixed $value)

Assigns a value to the specified offset.

offsetUnset(mixed $offset)

Unsets an offset.

int
count()

Returns the numner of items in the collection.

getIterator()

Retruns an array iterator object.

bool
isEmpty()

Returns TRUE if the collection is empty and FALSE if not.

int
unshift(mixed $item)

Prepends the passed item to the front of the collection and returns the new number of elements in the collection.

mixed
shift()

Shifts the first value of the collection off and returns it, shortening the collection by one element.

int
push(mixed $item)

Pushes the passed variable onto the end of the collection and returns the new number of elements in the collection.

mixed
pop()

Pops and returns the last value of the collection, shortening the collection by one element.

mixed
first()

Returns the first item of the collection or NULL if the collection is empty.

mixed
last()

Returns the last item of the collection or NULL if the collection is empty.

$this
sort(callable $comparator, bool $maintainIndexAssociation = true)

Sorts the collection using the specified comparator callable and returns TRUE on success and FALSE on failure.

chunk(int $size)

Chunks the collection into a collection containing $size sized collections.

$this
shuffle()

Shuffles the items in the collection and returns TRUE on success and FALSE on failure.

$this
each(callable $callable)

Applies the callable on all items in the collection.

map(callable $callable)

Returns a new collection where the callable has been applied to all the items.

filter(callable|null $callable = null)

Returns a new filtered collection.

with(array $keys)

Returns a new collection where all items not in the provided list have been removed.

without(array $keys)

Returns a new collection where all items in the provided list have been removed.

merge(Collection $collection)

Merges two collections.

Details

in ExtendableTrait at line 33
static addMethod(string $methodName, Closure $closure)

Adds a method to the class.

Parameters

string $methodName Method name
Closure $closure Closure

in ExtendableTrait at line 45
mixed __call(string $name, array $arguments)

Executes class extensions.

Parameters

string $name Method name
array $arguments Method arguments

Return Value

mixed

in ExtendableTrait at line 62
static mixed __callStatic(string $name, array $arguments)

Executes class extensions.

Parameters

string $name Method name
array $arguments Method arguments

Return Value

mixed

at line 59
__construct(array $items = [])

Constructor.

Parameters

array $items Collection items

at line 69
array getItems()

Returns all the items in the collection.

Return Value

array

at line 79
array getValues()

Returns all the values in the collection.

Return Value

array

at line 89
$this resetKeys()

Resets the collection keys.

Return Value

$this

at line 103
$this put(int|string $key, mixed $value)

Adds a new item to the collection.

Parameters

int|string $key Key
mixed $value Value

Return Value

$this

at line 116
bool has(int|string $key)

Returns TRUE if the item key exists and FALSE if not.

Parameters

int|string $key Key

Return Value

bool

at line 128
mixed get(int|string $key, mixed $default = null)

Returns an item from the collection.

Parameters

int|string $key Key
mixed $default Default value

Return Value

mixed

at line 144
$this remove(int|string $key)

Removes an item from the collection.

Parameters

int|string $key Key

Return Value

$this

at line 156
$this clear()

Clears the collection.

Return Value

$this

at line 169
bool offsetExists(mixed $offset)

Checks whether or not an offset exists.

Parameters

mixed $offset The offset to check for

Return Value

bool

at line 180
mixed offsetGet(mixed $offset)

Returns the value at the specified offset.

Parameters

mixed $offset The offset to retrieve

Return Value

mixed

at line 196
offsetSet(mixed $offset, mixed $value)

Assigns a value to the specified offset.

Parameters

mixed $offset The offset to assign the value to
mixed $value The value to set

at line 213
offsetUnset(mixed $offset)

Unsets an offset.

Parameters

mixed $offset The offset to unset

at line 223
int count()

Returns the numner of items in the collection.

Return Value

int

at line 233
ArrayIterator getIterator()

Retruns an array iterator object.

Return Value

ArrayIterator

at line 243
bool isEmpty()

Returns TRUE if the collection is empty and FALSE if not.

Return Value

bool

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.

Parameters

mixed $item Collection item

Return Value

int

at line 266
mixed shift()

Shifts the first value of the collection off and returns it, shortening the collection by one element.

Return Value

mixed

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.

Parameters

mixed $item Collection item

Return Value

int

at line 289
mixed pop()

Pops and returns the last value of the collection, shortening the collection by one element.

Return Value

mixed

at line 299
mixed first()

Returns the first item of the collection or NULL if the collection is empty.

Return Value

mixed

at line 316
mixed last()

Returns the last item of the collection or NULL if the collection is empty.

Return Value

mixed

at line 336
$this sort(callable $comparator, bool $maintainIndexAssociation = true)

Sorts the collection using the specified comparator callable and returns TRUE on success and FALSE on failure.

Parameters

callable $comparator Comparator callable
bool $maintainIndexAssociation Maintain index association?

Return Value

$this

at line 356
Collection chunk(int $size)

Chunks the collection into a collection containing $size sized collections.

Parameters

int $size Chunk size

Return Value

Collection

at line 374
$this shuffle()

Shuffles the items in the collection and returns TRUE on success and FALSE on failure.

Return Value

$this

at line 387
$this each(callable $callable)

Applies the callable on all items in the collection.

Parameters

callable $callable Callable

Return Value

$this

at line 404
Collection map(callable $callable)

Returns a new collection where the callable has been applied to all the items.

Parameters

callable $callable Callable

Return Value

Collection

at line 419
Collection filter(callable|null $callable = null)

Returns a new filtered collection.

Parameters

callable|null $callable Filter

Return Value

Collection

at line 435
Collection with(array $keys)

Returns a new collection where all items not in the provided list have been removed.

Parameters

array $keys Keys

Return Value

Collection

at line 446
Collection without(array $keys)

Returns a new collection where all items in the provided list have been removed.

Parameters

array $keys Keys

Return Value

Collection

at line 457
Collection merge(Collection $collection)

Merges two collections.

Parameters

Collection $collection Collection to merge

Return Value

Collection