Class Collection
Collection
This class provides a common interface used by many other
classes in a Slim application that manage "collections"
of data that must be inspected and/or manipulated
-
Slim\Collection
implements
Slim\Interfaces\CollectionInterface
Methods summary
public
|
#
__construct( array $items = [] )
Create new collection
Parameters
- $items
- Pre-populate collection with this key-value array
|
public
|
#
set( string $key, mixed $value )
Set collection item
Parameters
- $key
- The data key
- $value
- The data value
Implementation of
|
public
mixed
|
#
get( string $key, mixed $default = null )
Get collection item for key
Get collection item for key
Parameters
- $key
- The data key
- $default
- The default value to return if data key does not exist
Returns
mixed The key's value, or the default value
Implementation of
|
public
|
#
replace( array $items )
Add item to collection, replacing existing items with the same data key
Add item to collection, replacing existing items with the same data key
Parameters
- $items
- Key-value array of data to append to this collection
Implementation of
|
public
array
|
#
all( )
Get all items in collection
Get all items in collection
Returns
array The collection's source data
Implementation of
|
public
array
|
#
keys( )
Get collection keys
Returns
array The collection's source data keys
|
public
boolean
|
#
has( string $key )
Does this collection have a given key?
Does this collection have a given key?
Parameters
Returns
boolean
Implementation of
|
public
|
#
remove( string $key )
Remove item from collection
Remove item from collection
Parameters
Implementation of
|
public
|
#
clear( )
Remove all items from collection
Remove all items from collection
Implementation of
|
public
boolean
|
#
offsetExists( string $key )
Does this collection have a given key?
Does this collection have a given key?
Parameters
Returns
boolean
Implementation of
ArrayAccess::offsetExists()
|
public
mixed
|
#
offsetGet( string $key )
Get collection item for key
Get collection item for key
Parameters
Returns
mixed The key's value, or the default value
Implementation of
ArrayAccess::offsetGet()
|
public
|
#
offsetSet( string $key, mixed $value )
Set collection item
Parameters
- $key
- The data key
- $value
- The data value
Implementation of
ArrayAccess::offsetSet()
|
public
|
#
offsetUnset( string $key )
Remove item from collection
Remove item from collection
Parameters
Implementation of
ArrayAccess::offsetUnset()
|
public
integer
|
#
count( )
Get number of items in collection
Get number of items in collection
Returns
integer
Implementation of
Countable::count()
|
public
ArrayIterator
|
#
getIterator( )
Get collection iterator
Returns
ArrayIterator
Implementation of
IteratorAggregate::getIterator()
|