Collection
in package
implements
ArrayAccess, Countable, IteratorAggregate
Uses
ArrayAccessTrait, CountableTrait, IteratorAggregateTrait
A generic collection of items.
Tags
Table of Contents
Interfaces
- ArrayAccess
- Countable
- IteratorAggregate
Properties
- $data : array<string|int, TValue>
- Holds the iterable data.
Methods
- __construct() : void
- Create a collection of items.
- __get() : Item|null
- Magic method to read collection items as properties.
- __set() : void
- Magic method to write collection items as properties.
- add() : void
- Add an item to the collection.
- clear() : void
- Clear the collection of any items.
- copy() : Collection<string|int, Item>
- Get a new collection with the same set of items.
- get() : Item|null
- Get the item at the specified index.
- isEmpty() : bool
- Check if collection is empty.
- remove() : void
- Remove an item from the collection.
- set() : void
- Set the item at the specified index.
- toArray() : array<string|int, Item>
- Return array representation of collection.
Properties
$data
Holds the iterable data.
protected
array<string|int, TValue>
$data
= []
Methods
__construct()
Create a collection of items.
public
__construct([array<string|int, Item> $items = [] ]) : void
Parameters
- $items : array<string|int, Item> = []
-
Initial set of items
__get()
Magic method to read collection items as properties.
public
__get(string|int $key) : Item|null
Parameters
- $key : string|int
-
The item's index
Return values
Item|null —The item or NULL if key is invalid
__set()
Magic method to write collection items as properties.
public
__set(string|int $key, Item $item) : void
Parameters
- $key : string|int
-
The new item's index
- $item : Item
-
The new item
add()
Add an item to the collection.
public
add(Item $item) : void
Parameters
- $item : Item
-
The new item
clear()
Clear the collection of any items.
public
clear() : void
copy()
Get a new collection with the same set of items.
public
copy() : Collection<string|int, Item>
Return values
Collection<string|int, Item> —The new collection with the same items
get()
Get the item at the specified index.
public
get(string|int $key) : Item|null
Parameters
- $key : string|int
-
The item's index
Return values
Item|null —The item or NULL if key is invalid
isEmpty()
Check if collection is empty.
public
isEmpty() : bool
Return values
bool —Whether the collection contains any items
remove()
Remove an item from the collection.
public
remove(string|int $key) : void
Parameters
- $key : string|int
-
The item's key
set()
Set the item at the specified index.
public
set(string|int $key, Item $item) : void
Parameters
- $key : string|int
-
The new item's index
- $item : Item
-
The new item
toArray()
Return array representation of collection.
public
toArray() : array<string|int, Item>
Return values
array<string|int, Item> —Array of collection items