Overview

Namespaces

  • Illuminate
    • Support
      • Contracts
    • Test
  • PHP

Classes

  • Collection
  • Overview
  • Namespace
  • Class
  • Tree

Class Collection

Illuminate\Support\Collection implements ArrayAccess, Illuminate\Support\Contracts\ArrayableInterface, Countable, IteratorAggregate, Illuminate\Support\Contracts\JsonableInterface, JsonSerializable
Namespace: Illuminate\Support
Located at mechanicious/Support/Collection.php
Methods summary
public
# __construct( array $items = array() )

Create a new collection.

Create a new collection.

Parameters

$items
array
$items
public static Illuminate\Support\Collection
# make( mixed $items )

Create a new collection instance if the value isn't one already.

Create a new collection instance if the value isn't one already.

Parameters

$items
mixed
$items

Returns

Illuminate\Support\Collection
public array
# all( )

Get all of the items in the collection.

Get all of the items in the collection.

Returns

array
public Illuminate\Support\Collection
# collapse( )

Collapse the collection items into a single array.

Collapse the collection items into a single array.

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# diff( Illuminate\Support\Collection|Illuminate\Support\Contracts\ArrayableInterface|array $items )

Diff the collection with the given items.

Diff the collection with the given items.

Parameters

$items
Illuminate\Support\Collection|Illuminate\Support\Contracts\ArrayableInterface|array
$items

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# each( Closure $callback )

Execute a callback over each item.

Execute a callback over each item.

Parameters

$callback
Closure
$callback

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# fetch( string $key )

Fetch a nested element of the collection.

Fetch a nested element of the collection.

Parameters

$key
string
$key

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# filter( Closure $callback )

Run a filter over each of the items.

Run a filter over each of the items.

Parameters

$callback
Closure
$callback

Returns

Illuminate\Support\Collection
public mixed|null
# first( Closure $callback = null, mixed $default = null )

Get the first item from the collection.

Get the first item from the collection.

Parameters

$callback
Closure
$callback
$default
mixed
$default

Returns

mixed|null
public array
# flatten( )

Get a flattened array of the items in the collection.

Get a flattened array of the items in the collection.

Returns

array
public
# forget( mixed $key )

Remove an item from the collection by key.

Remove an item from the collection by key.

Parameters

$key
mixed
$key
public mixed
# get( mixed $key, mixed $default = null )

Get an item from the collection by key.

Get an item from the collection by key.

Parameters

$key
mixed
$key
$default
mixed
$default

Returns

mixed
public Illuminate\Support\Collection
# groupBy( callable|string $groupBy )

Group an associative array by a field or Closure value.

Group an associative array by a field or Closure value.

Parameters

$groupBy
callable|string
$groupBy

Returns

Illuminate\Support\Collection
public boolean
# has( mixed $key )

Determine if an item exists in the collection by key.

Determine if an item exists in the collection by key.

Parameters

$key
mixed
$key

Returns

boolean
public string
# implode( string $value, string $glue = null )

Concatenate values of a given key as a string.

Concatenate values of a given key as a string.

Parameters

$value
string
$value
$glue
string
$glue

Returns

string
public Illuminate\Support\Collection
# intersect( Illuminate\Support\Collection|Illuminate\Support\Contracts\ArrayableInterface|array $items )

Intersect the collection with the given items.

Intersect the collection with the given items.

Parameters

$items
Illuminate\Support\Collection|Illuminate\Support\Contracts\ArrayableInterface|array
$items

Returns

Illuminate\Support\Collection
public boolean
# isEmpty( )

Determine if the collection is empty or not.

Determine if the collection is empty or not.

Returns

boolean
public mixed|null
# last( )

Get the last item from the collection.

Get the last item from the collection.

Returns

mixed|null
public array
# lists( string $value, string $key = null )

Get an array with the values of a given key.

Get an array with the values of a given key.

Parameters

$value
string
$value
$key
string
$key

Returns

array
public Illuminate\Support\Collection
# map( Closure $callback )

Run a map over each of the items.

Run a map over each of the items.

Parameters

$callback
Closure
$callback

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# merge( Illuminate\Support\Collection|Illuminate\Support\Contracts\ArrayableInterface|array $items )

Merge the collection with the given items.

Merge the collection with the given items.

Parameters

$items
Illuminate\Support\Collection|Illuminate\Support\Contracts\ArrayableInterface|array
$items

Returns

Illuminate\Support\Collection
public mixed|null
# pop( )

Get and remove the last item from the collection.

Get and remove the last item from the collection.

Returns

mixed|null
public
# prepend( mixed $value )

Push an item onto the beginning of the collection.

Push an item onto the beginning of the collection.

Parameters

$value
mixed
$value
public
# push( mixed $value )

Push an item onto the end of the collection.

Push an item onto the end of the collection.

Parameters

$value
mixed
$value
public mixed
# pull( mixed $key, mixed $default = null )

Pulls an item from the collection.

Pulls an item from the collection.

Parameters

$key
mixed
$key
$default
mixed
$default

Returns

mixed
public
# put( mixed $key, mixed $value )

Put an item in the collection by key.

Put an item in the collection by key.

Parameters

$key
mixed
$key
$value
mixed
$value
public mixed
# random( integer $amount = 1 )

Get one or more items randomly from the collection.

Get one or more items randomly from the collection.

Parameters

$amount
integer
$amount

Returns

mixed
public mixed
# reduce( callable $callback, mixed $initial = null )

Reduce the collection to a single value.

Reduce the collection to a single value.

Parameters

$callback
callable
$callback
$initial
mixed
$initial

Returns

mixed
public Illuminate\Support\Collection
# reject( Closure|mixed $callback )

Create a colleciton of all elements that do not pass a given truth test.

Create a colleciton of all elements that do not pass a given truth test.

Parameters

$callback
Closure|mixed
$callback

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# reverse( )

Reverse items order.

Reverse items order.

Returns

Illuminate\Support\Collection
public mixed
# search( mixed $value, boolean $strict = false )

Search the collection for a given value and return the corresponding key if successful.

Search the collection for a given value and return the corresponding key if successful.

Parameters

$value
mixed
$value
$strict
boolean
$strict

Returns

mixed
public mixed|null
# shift( )

Get and remove the first item from the collection.

Get and remove the first item from the collection.

Returns

mixed|null
public Illuminate\Support\Collection
# slice( integer $offset, integer $length = null, boolean $preserveKeys = false )

Slice the underlying collection array.

Slice the underlying collection array.

Parameters

$offset
integer
$offset
$length
integer
$length
$preserveKeys
boolean
$preserveKeys

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# chunk( integer $size, boolean $preserveKeys = false )

Chunk the underlying collection array.

Chunk the underlying collection array.

Parameters

$size
integer
$size
$preserveKeys
boolean
$preserveKeys

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# sort( Closure $callback )

Sort through each item with a callback.

Sort through each item with a callback.

Parameters

$callback
Closure
$callback

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# sortBy( Closure|string $callback, integer $options = SORT_REGULAR, boolean $descending = false )

Sort the collection using the given Closure.

Sort the collection using the given Closure.

Parameters

$callback
Closure|string
$callback
$options
integer
$options
$descending
boolean
$descending

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# sortByDesc( Closure|string $callback, integer $options = SORT_REGULAR )

Sort the collection in descending order using the given Closure.

Sort the collection in descending order using the given Closure.

Parameters

$callback
Closure|string
$callback
$options
integer
$options

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# splice( integer $offset, integer $length = 0, mixed $replacement = array() )

Splice portion of the underlying collection array.

Splice portion of the underlying collection array.

Parameters

$offset
integer
$offset
$length
integer
$length
$replacement
mixed
$replacement

Returns

Illuminate\Support\Collection
public mixed
# sum( Closure $callback )

Get the sum of the given values.

Get the sum of the given values.

Parameters

$callback
Closure
$callback

Returns

mixed
public Illuminate\Support\Collection
# take( integer $limit = null )

Take the first or last {$limit} items.

Take the first or last {$limit} items.

Parameters

$limit
integer
$limit

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# transform( Closure $callback )

Transform each item in the collection using a callback.

Transform each item in the collection using a callback.

Parameters

$callback
Closure
$callback

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# unique( )

Return only unique items from the collection array.

Return only unique items from the collection array.

Returns

Illuminate\Support\Collection
public Illuminate\Support\Collection
# values( )

Reset the keys on the underlying array.

Reset the keys on the underlying array.

Returns

Illuminate\Support\Collection
protected Closure
# valueRetriever( string $value )

Get a value retrieving callback.

Get a value retrieving callback.

Parameters

$value
string
$value

Returns

Closure
public array
# toArray( )

Get the collection of items as a plain array.

Get the collection of items as a plain array.

Returns

array

Implementation of

Illuminate\Support\Contracts\ArrayableInterface::toArray()
public array
# jsonSerialize( )

Convert the object into something JSON serializable.

Convert the object into something JSON serializable.

Returns

array

Implementation of

JsonSerializable::jsonSerialize()
public string
# toJson( integer $options = 0 )

Get the collection of items as JSON.

Get the collection of items as JSON.

Parameters

$options
integer
$options

Returns

string

Implementation of

Illuminate\Support\Contracts\JsonableInterface::toJson()
public ArrayIterator
# getIterator( )

Get an iterator for the items.

Get an iterator for the items.

Returns

ArrayIterator

Implementation of

IteratorAggregate::getIterator()
public CachingIterator
# getCachingIterator( mixed $flags = Illuminate\Support\CachingIterator::CALL_TOSTRING )

Get a CachingIterator instance.

Get a CachingIterator instance.

Returns

CachingIterator
public integer
# count( )

Count the number of items in the collection.

Count the number of items in the collection.

Returns

integer

Implementation of

Countable::count()
public boolean
# offsetExists( mixed $key )

Determine if an item exists at an offset.

Determine if an item exists at an offset.

Parameters

$key
mixed
$key

Returns

boolean

Implementation of

ArrayAccess::offsetExists()
public mixed
# offsetGet( mixed $key )

Get an item at a given offset.

Get an item at a given offset.

Parameters

$key
mixed
$key

Returns

mixed

Implementation of

ArrayAccess::offsetGet()
public
# offsetSet( mixed $key, mixed $value )

Set the item at a given offset.

Set the item at a given offset.

Parameters

$key
mixed
$key
$value
mixed
$value

Implementation of

ArrayAccess::offsetSet()
public
# offsetUnset( string $key )

Unset the item at a given offset.

Unset the item at a given offset.

Parameters

$key
string
$key

Implementation of

ArrayAccess::offsetUnset()
public string
# __toString( )

Convert the collection to its string representation.

Convert the collection to its string representation.

Returns

string
protected array
# getArrayableItems( Illuminate\Support\Collection|Illuminate\Support\Contracts\ArrayableInterface|array $items )

Results array of items from Collection or ArrayableInterface.

Results array of items from Collection or ArrayableInterface.

Parameters

$items
Illuminate\Support\Collection|Illuminate\Support\Contracts\ArrayableInterface|array
$items

Returns

array
Properties summary
protected array $items array()
#

The items contained in the collection.

The items contained in the collection.

API documentation generated by ApiGen 2.8.0