PHP Class Illuminate\Support\Collection

Inheritance: implements ArrayAcces\ArrayAccess, implements Illuminate\Support\Contracts\ArrayableInterface, implements Countabl\Countable, implements IteratorAggregat\IteratorAggregate, implements Illuminate\Support\Contracts\JsonableInterface
Afficher le fichier Open project: tightenco/collect Class Usage Examples

Protected Properties

Свойство Type Description
$items array The items contained in the collection.

Méthodes publiques

Méthode Description
__construct ( mixed $items = [] ) : void Create a new collection.
__toString ( ) : string Convert the collection to its string representation.
all ( ) : array Get all of the items in the collection.
average ( callable | string | null $callback = null ) : mixed Alias for the "avg" method.
avg ( callable | string | null $callback = null ) : mixed Get the average value of a given key.
chunk ( integer $size ) : static Chunk the underlying collection array.
collapse ( ) : static Collapse the collection of items into a single array.
combine ( mixed $values ) : static Create a collection by using this collection for keys and another for its values.
contains ( mixed $key, mixed $value = null ) : boolean Determine if an item exists in the collection.
containsStrict ( mixed $key, mixed $value = null ) : boolean Determine if an item exists in the collection using strict comparison.
count ( ) : integer Count the number of items in the collection.
diff ( mixed $items ) : static Get the items in the collection that are not present in the given items.
diffKeys ( mixed $items ) : static Get the items in the collection whose keys are not present in the given items.
each ( callable $callback ) Execute a callback over each item.
every ( integer $step, integer $offset ) : static Create a new collection consisting of every n-th element.
except ( mixed $keys ) : static Get all items except for those with the specified keys.
filter ( callable $callback = null ) : static Run a filter over each of the items.
first ( callable $callback = null, mixed $default = null ) : mixed Get the first item from the collection.
flatMap ( callable $callback ) : static Map a collection and flatten the result by a single level.
flatten ( integer $depth = INF ) : static Get a flattened array of the items in the collection.
flip ( ) : static Flip the items in the collection.
forPage ( integer $page, integer $perPage ) : static "Paginate" the collection by slicing it into a smaller collection.
forget ( string | array $keys ) Remove an item from the collection by key.
get ( mixed $key, mixed $default = null ) : mixed Get an item from the collection by key.
getCachingIterator ( integer $flags = CachingIterator::CALL_TOSTRING ) : CachingIterator Get a CachingIterator instance.
getIterator ( ) : ArrayIterator Get an iterator for the items.
groupBy ( callable | string $groupBy, boolean $preserveKeys = false ) : static Group an associative array by a field or using a callback.
has ( mixed $key ) : boolean Determine if an item exists in the collection by key.
implode ( string $value, string $glue = null ) : string Concatenate values of a given key as a string.
intersect ( mixed $items ) : static Intersect the collection with the given items.
isEmpty ( ) : boolean Determine if the collection is empty or not.
jsonSerialize ( ) : array Convert the object into something JSON serializable.
keyBy ( callable | string $keyBy ) : static Key an associative array by a field or using a callback.
keys ( ) : static Get the keys of the collection items.
last ( callable $callback = null, mixed $default = null ) : mixed Get the last item from the collection.
make ( mixed $items = [] ) : static Create a new collection instance if the value isn't one already.
map ( callable $callback ) : static Run a map over each of the items.
mapWithKeys ( callable $callback ) : static Run an associative map over each of the items.
max ( callable | string | null $callback = null ) : mixed Get the max value of a given key.
median ( null $key = null ) : mixed | null Get the median of a given key.
merge ( mixed $items ) : static Merge the collection with the given items.
min ( callable | string | null $callback = null ) : mixed Get the min value of a given key.
mode ( null $key = null ) : array Get the mode of a given key.
offsetExists ( mixed $key ) : boolean Determine if an item exists at an offset.
offsetGet ( mixed $key ) : mixed Get an item at a given offset.
offsetSet ( mixed $key, mixed $value ) : void Set the item at a given offset.
offsetUnset ( string $key ) : void Unset the item at a given offset.
only ( mixed $keys ) : static Get the items with the specified keys.
pipe ( callable $callback ) : mixed Pass the collection to the given callback and return the result.
pluck ( string $value, string | null $key = null ) : static Get the values of a given key.
pop ( ) : mixed Get and remove the last item from the collection.
prepend ( mixed $value, mixed $key = null ) Push an item onto the beginning of the collection.
pull ( mixed $key, mixed $default = null ) : mixed Get and remove an item from the collection.
push ( mixed $value ) Push an item onto the end of the collection.
put ( mixed $key, mixed $value ) Put an item in the collection by key.
random ( integer $amount = 1 ) : mixed Get one or more items randomly from the collection.
reduce ( callable $callback, mixed $initial = null ) : mixed Reduce the collection to a single value.
reject ( callable | mixed $callback ) : static Create a collection of all elements that do not pass a given truth test.
reverse ( ) : static Reverse items order.
search ( mixed $value, boolean $strict = false ) : mixed Search the collection for a given value and return the corresponding key if successful.
shift ( ) : mixed Get and remove the first item from the collection.
shuffle ( integer $seed = null ) : static Shuffle the items in the collection.
slice ( integer $offset, integer $length = null ) : static Slice the underlying collection array.
sort ( callable $callback = null ) : static Sort through each item with a callback.
sortBy ( callable | string $callback, integer $options = SORT_REGULAR, boolean $descending = false ) : static Sort the collection using the given callback.
sortByDesc ( callable | string $callback, integer $options = SORT_REGULAR ) : static Sort the collection in descending order using the given callback.
splice ( integer $offset, integer | null $length = null, mixed $replacement = [] ) : static Splice a portion of the underlying collection array.
split ( integer $numberOfGroups ) : static Split a collection into a certain number of groups.
sum ( callable | string | null $callback = null ) : mixed Get the sum of the given values.
take ( integer $limit ) : static Take the first or last {$limit} items.
toArray ( ) : array Get the collection of items as a plain array.
toBase ( ) : Collection Get a base Support collection instance from this collection.
toJson ( integer $options ) : string Get the collection of items as JSON.
transform ( callable $callback ) Transform each item in the collection using a callback.
union ( mixed $items ) : static Union the collection with the given items.
unique ( string | callable | null $key = null, boolean $strict = false ) : static Return only unique items from the collection array.
uniqueStrict ( string | callable | null $key = null ) : static Return only unique items from the collection array using strict comparison.
values ( ) : static Reset the keys on the underlying array.
where ( string $key, mixed $operator, mixed $value = null ) : static Filter items by the given key value pair.
whereIn ( string $key, mixed $values, boolean $strict = false ) : static Filter items by the given key value pair.
whereInStrict ( string $key, mixed $values ) : static Filter items by the given key value pair using strict comparison.
whereStrict ( string $key, mixed $value ) : static Filter items by the given key value pair using strict comparison.
zip ( $items ) : static Zip the collection together with one or more arrays.

Méthodes protégées

Méthode Description
getArrayableItems ( mixed $items ) : array Results array of items from Collection or Arrayable.
operatorForWhere ( string $key, string $operator, mixed $value ) : Closure Get an operator checker callback.
useAsCallable ( mixed $value ) : boolean Determine if the given value is callable, but not a string.
valueRetriever ( string $value ) : callable Get a value retrieving callback.

Method Details

__construct() public méthode

Create a new collection.
public __construct ( mixed $items = [] ) : void
$items mixed
Résultat void

__toString() public méthode

Convert the collection to its string representation.
public __toString ( ) : string
Résultat string

all() public méthode

Get all of the items in the collection.
public all ( ) : array
Résultat array

average() public méthode

Alias for the "avg" method.
public average ( callable | string | null $callback = null ) : mixed
$callback callable | string | null
Résultat mixed

avg() public méthode

Get the average value of a given key.
public avg ( callable | string | null $callback = null ) : mixed
$callback callable | string | null
Résultat mixed

chunk() public méthode

Chunk the underlying collection array.
public chunk ( integer $size ) : static
$size integer
Résultat static

collapse() public méthode

Collapse the collection of items into a single array.
public collapse ( ) : static
Résultat static

combine() public méthode

Create a collection by using this collection for keys and another for its values.
public combine ( mixed $values ) : static
$values mixed
Résultat static

contains() public méthode

Determine if an item exists in the collection.
public contains ( mixed $key, mixed $value = null ) : boolean
$key mixed
$value mixed
Résultat boolean

containsStrict() public méthode

Determine if an item exists in the collection using strict comparison.
public containsStrict ( mixed $key, mixed $value = null ) : boolean
$key mixed
$value mixed
Résultat boolean

count() public méthode

Count the number of items in the collection.
public count ( ) : integer
Résultat integer

diff() public méthode

Get the items in the collection that are not present in the given items.
public diff ( mixed $items ) : static
$items mixed
Résultat static

diffKeys() public méthode

Get the items in the collection whose keys are not present in the given items.
public diffKeys ( mixed $items ) : static
$items mixed
Résultat static

each() public méthode

Execute a callback over each item.
public each ( callable $callback )
$callback callable

every() public méthode

Create a new collection consisting of every n-th element.
public every ( integer $step, integer $offset ) : static
$step integer
$offset integer
Résultat static

except() public méthode

Get all items except for those with the specified keys.
public except ( mixed $keys ) : static
$keys mixed
Résultat static

filter() public méthode

Run a filter over each of the items.
public filter ( callable $callback = null ) : static
$callback callable
Résultat static

first() public méthode

Get the first item from the collection.
public first ( callable $callback = null, mixed $default = null ) : mixed
$callback callable
$default mixed
Résultat mixed

flatMap() public méthode

Map a collection and flatten the result by a single level.
public flatMap ( callable $callback ) : static
$callback callable
Résultat static

flatten() public méthode

Get a flattened array of the items in the collection.
public flatten ( integer $depth = INF ) : static
$depth integer
Résultat static

flip() public méthode

Flip the items in the collection.
public flip ( ) : static
Résultat static

forPage() public méthode

"Paginate" the collection by slicing it into a smaller collection.
public forPage ( integer $page, integer $perPage ) : static
$page integer
$perPage integer
Résultat static

forget() public méthode

Remove an item from the collection by key.
public forget ( string | array $keys )
$keys string | array

get() public méthode

Get an item from the collection by key.
public get ( mixed $key, mixed $default = null ) : mixed
$key mixed
$default mixed
Résultat mixed

getArrayableItems() protected méthode

Results array of items from Collection or Arrayable.
protected getArrayableItems ( mixed $items ) : array
$items mixed
Résultat array

getCachingIterator() public méthode

Get a CachingIterator instance.
public getCachingIterator ( integer $flags = CachingIterator::CALL_TOSTRING ) : CachingIterator
$flags integer
Résultat CachingIterator

getIterator() public méthode

Get an iterator for the items.
public getIterator ( ) : ArrayIterator
Résultat ArrayIterator

groupBy() public méthode

Group an associative array by a field or using a callback.
public groupBy ( callable | string $groupBy, boolean $preserveKeys = false ) : static
$groupBy callable | string
$preserveKeys boolean
Résultat static

has() public méthode

Determine if an item exists in the collection by key.
public has ( mixed $key ) : boolean
$key mixed
Résultat boolean

implode() public méthode

Concatenate values of a given key as a string.
public implode ( string $value, string $glue = null ) : string
$value string
$glue string
Résultat string

intersect() public méthode

Intersect the collection with the given items.
public intersect ( mixed $items ) : static
$items mixed
Résultat static

isEmpty() public méthode

Determine if the collection is empty or not.
public isEmpty ( ) : boolean
Résultat boolean

jsonSerialize() public méthode

Convert the object into something JSON serializable.
public jsonSerialize ( ) : array
Résultat array

keyBy() public méthode

Key an associative array by a field or using a callback.
public keyBy ( callable | string $keyBy ) : static
$keyBy callable | string
Résultat static

keys() public méthode

Get the keys of the collection items.
public keys ( ) : static
Résultat static

last() public méthode

Get the last item from the collection.
public last ( callable $callback = null, mixed $default = null ) : mixed
$callback callable
$default mixed
Résultat mixed

make() public static méthode

Create a new collection instance if the value isn't one already.
public static make ( mixed $items = [] ) : static
$items mixed
Résultat static

map() public méthode

Run a map over each of the items.
public map ( callable $callback ) : static
$callback callable
Résultat static

mapWithKeys() public méthode

The callback should return an associative array with a single key/value pair.
public mapWithKeys ( callable $callback ) : static
$callback callable
Résultat static

max() public méthode

Get the max value of a given key.
public max ( callable | string | null $callback = null ) : mixed
$callback callable | string | null
Résultat mixed

median() public méthode

Get the median of a given key.
public median ( null $key = null ) : mixed | null
$key null
Résultat mixed | null

merge() public méthode

Merge the collection with the given items.
public merge ( mixed $items ) : static
$items mixed
Résultat static

min() public méthode

Get the min value of a given key.
public min ( callable | string | null $callback = null ) : mixed
$callback callable | string | null
Résultat mixed

mode() public méthode

Get the mode of a given key.
public mode ( null $key = null ) : array
$key null
Résultat array

offsetExists() public méthode

Determine if an item exists at an offset.
public offsetExists ( mixed $key ) : boolean
$key mixed
Résultat boolean

offsetGet() public méthode

Get an item at a given offset.
public offsetGet ( mixed $key ) : mixed
$key mixed
Résultat mixed

offsetSet() public méthode

Set the item at a given offset.
public offsetSet ( mixed $key, mixed $value ) : void
$key mixed
$value mixed
Résultat void

offsetUnset() public méthode

Unset the item at a given offset.
public offsetUnset ( string $key ) : void
$key string
Résultat void

only() public méthode

Get the items with the specified keys.
public only ( mixed $keys ) : static
$keys mixed
Résultat static

operatorForWhere() protected méthode

Get an operator checker callback.
protected operatorForWhere ( string $key, string $operator, mixed $value ) : Closure
$key string
$operator string
$value mixed
Résultat Closure

pipe() public méthode

Pass the collection to the given callback and return the result.
public pipe ( callable $callback ) : mixed
$callback callable
Résultat mixed

pluck() public méthode

Get the values of a given key.
public pluck ( string $value, string | null $key = null ) : static
$value string
$key string | null
Résultat static

pop() public méthode

Get and remove the last item from the collection.
public pop ( ) : mixed
Résultat mixed

prepend() public méthode

Push an item onto the beginning of the collection.
public prepend ( mixed $value, mixed $key = null )
$value mixed
$key mixed

pull() public méthode

Get and remove an item from the collection.
public pull ( mixed $key, mixed $default = null ) : mixed
$key mixed
$default mixed
Résultat mixed

push() public méthode

Push an item onto the end of the collection.
public push ( mixed $value )
$value mixed

put() public méthode

Put an item in the collection by key.
public put ( mixed $key, mixed $value )
$key mixed
$value mixed

random() public méthode

Get one or more items randomly from the collection.
public random ( integer $amount = 1 ) : mixed
$amount integer
Résultat mixed

reduce() public méthode

Reduce the collection to a single value.
public reduce ( callable $callback, mixed $initial = null ) : mixed
$callback callable
$initial mixed
Résultat mixed

reject() public méthode

Create a collection of all elements that do not pass a given truth test.
public reject ( callable | mixed $callback ) : static
$callback callable | mixed
Résultat static

reverse() public méthode

Reverse items order.
public reverse ( ) : static
Résultat static

shift() public méthode

Get and remove the first item from the collection.
public shift ( ) : mixed
Résultat mixed

shuffle() public méthode

Shuffle the items in the collection.
public shuffle ( integer $seed = null ) : static
$seed integer
Résultat static

slice() public méthode

Slice the underlying collection array.
public slice ( integer $offset, integer $length = null ) : static
$offset integer
$length integer
Résultat static

sort() public méthode

Sort through each item with a callback.
public sort ( callable $callback = null ) : static
$callback callable
Résultat static

sortBy() public méthode

Sort the collection using the given callback.
public sortBy ( callable | string $callback, integer $options = SORT_REGULAR, boolean $descending = false ) : static
$callback callable | string
$options integer
$descending boolean
Résultat static

sortByDesc() public méthode

Sort the collection in descending order using the given callback.
public sortByDesc ( callable | string $callback, integer $options = SORT_REGULAR ) : static
$callback callable | string
$options integer
Résultat static

splice() public méthode

Splice a portion of the underlying collection array.
public splice ( integer $offset, integer | null $length = null, mixed $replacement = [] ) : static
$offset integer
$length integer | null
$replacement mixed
Résultat static

split() public méthode

Split a collection into a certain number of groups.
public split ( integer $numberOfGroups ) : static
$numberOfGroups integer
Résultat static

sum() public méthode

Get the sum of the given values.
public sum ( callable | string | null $callback = null ) : mixed
$callback callable | string | null
Résultat mixed

take() public méthode

Take the first or last {$limit} items.
public take ( integer $limit ) : static
$limit integer
Résultat static

toArray() public méthode

Get the collection of items as a plain array.
public toArray ( ) : array
Résultat array

toBase() public méthode

Get a base Support collection instance from this collection.
public toBase ( ) : Collection
Résultat Collection

toJson() public méthode

Get the collection of items as JSON.
public toJson ( integer $options ) : string
$options integer
Résultat string

transform() public méthode

Transform each item in the collection using a callback.
public transform ( callable $callback )
$callback callable

union() public méthode

Union the collection with the given items.
public union ( mixed $items ) : static
$items mixed
Résultat static

unique() public méthode

Return only unique items from the collection array.
public unique ( string | callable | null $key = null, boolean $strict = false ) : static
$key string | callable | null
$strict boolean
Résultat static

uniqueStrict() public méthode

Return only unique items from the collection array using strict comparison.
public uniqueStrict ( string | callable | null $key = null ) : static
$key string | callable | null
Résultat static

useAsCallable() protected méthode

Determine if the given value is callable, but not a string.
protected useAsCallable ( mixed $value ) : boolean
$value mixed
Résultat boolean

valueRetriever() protected méthode

Get a value retrieving callback.
protected valueRetriever ( string $value ) : callable
$value string
Résultat callable

values() public méthode

Reset the keys on the underlying array.
public values ( ) : static
Résultat static

where() public méthode

Filter items by the given key value pair.
public where ( string $key, mixed $operator, mixed $value = null ) : static
$key string
$operator mixed
$value mixed
Résultat static

whereIn() public méthode

Filter items by the given key value pair.
public whereIn ( string $key, mixed $values, boolean $strict = false ) : static
$key string
$values mixed
$strict boolean
Résultat static

whereInStrict() public méthode

Filter items by the given key value pair using strict comparison.
public whereInStrict ( string $key, mixed $values ) : static
$key string
$values mixed
Résultat static

whereStrict() public méthode

Filter items by the given key value pair using strict comparison.
public whereStrict ( string $key, mixed $value ) : static
$key string
$value mixed
Résultat static

zip() public méthode

e.g. new Collection([1, 2, 3])->zip([4, 5, 6]); => [[1, 4], [2, 5], [3, 6]]
public zip ( $items ) : static
$items
Résultat static

Property Details

$items protected_oe property

The items contained in the collection.
protected array $items
Résultat array