PHP Basics

Collection
in package
implements ArrayAccess, Countable, IteratorAggregate Uses ArrayAccessTrait, CountableTrait, IteratorAggregateTrait

A generic collection of items.

Tags
author

Sebastian Meyer sebastian.meyer@opencultureconsulting.com

template

Item of mixed

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

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
APIYes
Parameters
$item : Item

The new item

clear()

Clear the collection of any items.

public clear() : void
APIYes

copy()

Get a new collection with the same set of items.

public copy() : Collection<string|int, Item>
APIYes
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
APIYes
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
APIYes
Return values
bool

Whether the collection contains any items

remove()

Remove an item from the collection.

public remove(string|int $key) : void
APIYes
Parameters
$key : string|int

The item's key

set()

Set the item at the specified index.

public set(string|int $key, Item $item) : void
APIYes
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>
APIYes
Return values
array<string|int, Item>

Array of collection items


        
On this page

Search results