com\setasign\SetaFramework\Collection
Collection Class Collection
File: /SetaFramework/src/Collection/Collection.php
Class hierarchy
Implements
Summary
Methods
- __construct()
- __toString()
- all()
- asort()
- chunk()
- count()
- delete()
- each()
- every()
- except()
- filter()
- first()
- flatten()
- flip()
- get()
- getIterator()
- has()
- implode()
- in()
- jsonSerialize()
- keys()
- ksort()
- last()
- map()
- offsetExists()
- offsetGet()
- offsetSet()
- offsetUnset()
- only()
- pipe()
- pipeCollection()
- pop()
- prepend()
- pull()
- push()
- put()
- random()
- reduce()
- reverse()
- search()
- shift()
- shuffle()
- slice()
- sort()
- toArray()
- transform()
- uasort()
- union()
- unique()
- usort()
- values()
Properties
$items
Static Methods
explode()
string $string,
?int $limit = null
Parameters
- $delimiter: string
- $string: string
- $limit: ?int
Methods
chunk()
Split the collection into chunks
Parameters
- $size: int
- $preserveKeys: bool
Return Values
Returns a new instance.
each()
Execute a callback over each item
Parameters
- $callback: callable
If the callback returns false the remaining elements will be skipped.
every()
Create a new collection consisting of every n-th element
Parameters
- $step: int
- $offset: int
Return Values
Returns a new instance.
except()
Get all items except for those with the specified keys
Parameters
- $keys: int|string
Return Values
Returns a new instance.
filter()
int $flag = \ARRAY_FILTER_USE_BOTH
Filters elements of an array using a callback function
The keys will be preserved.
Parameters
- $callback: ?callable
- $flag: int
Return Values
Returns a new instance.
See
flip()
Exchanges all keys with their associated values in an array
Return Values
Returns a new instance.
See
get()
Get an item from the collection by key
Parameters
- $key: mixed
- $default: ?mixed
Will be returned if the item doesn't exist
map()
Applies the callback to the elements of the given arrays
Parameters
- $callable: callable
- $arrays: array
Return Values
Returns a new instance.
See
only()
Get all items with the specified keys
Parameters
- $keys: int|string
Return Values
Returns a new instance.
pipe()
Pass the collection to the given callback and return the result
Templates
- ReturnType
Parameters
- $callable: callable(
static
): ReturnType
pipeCollection()
Pass the collection to the given callback and return the result
Like pipe but the result must be a collection too!
Parameters
- $callable: callable
pull()
Pulls an item out of the collection
Parameters
- $key: null|int|string
- $default: mixed
Will be returned if the item doesn't exist
See
put()
Puts an item onto the end of the collection
Parameters
- $key: null|int|string
- $value: mixed
Will be returned if the item doesn't exist
random()
Pick one or more random entries out of the collection
Parameters
- $amount: int
Must be >= 0 and <= count()
- $preserveKeys: bool
Return Values
Returns a new instance.
reduce()
Iteratively reduce the collection to a single value using a callback function
Parameters
- $callback: callable
Callback
mixed callback ( mixed $carry , mixed $item )- $initial: mixed
See
reverse()
Return a new collection with elements in reverse order
Return Values
Returns a new instance.
See
search()
Searches the collection for a given value and returns the first corresponding key if successful
Parameters
- $value: mixed
- $strict: bool
Return Values
Returns the key for $value if it is found in the array, FALSE otherwise.
See
slice()
?int $length = null,
bool $preserveKeys = false
Extract a slice of the array
Parameters
- $offset: int
- $length: ?int
- $preserveKeys: bool
Return Values
Returns a new instance.
See
transform()
Transform each item in the collection using a callback
Parameters
- $callable: callable
- $withKeys: bool
See
uasort()
Sort the collection with a user-defined comparison function and maintain index association
Parameters
- $callable: callable
See
union()
Union this collection with one or multiple arrays
Parameters
- $arrays: array
Return Values
Returns a new instance.
unique()
Removes duplicate values from an array
Parameters
- $sortFlags: int
Return Values
Returns a new instance.
usort()
Sort the collection by values using a user-defined comparison function
Parameters
- $callable: callable
