PHP Класс Illuminate\Support\Collection

Наследование: implements ArrayAcces\ArrayAccess, implements Illuminate\Support\Contracts\ArrayableInterface, implements Countabl\Countable, implements IteratorAggregat\IteratorAggregate, implements Illuminate\Support\Contracts\JsonableInterface
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$items array The items contained in the collection.

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Описание методов

__construct() публичный метод

Create a new collection.
public __construct ( mixed $items = [] ) : void
$items mixed
Результат void

__toString() публичный метод

Convert the collection to its string representation.
public __toString ( ) : string
Результат string

all() публичный метод

Get all of the items in the collection.
public all ( ) : array
Результат array

average() публичный метод

Alias for the "avg" method.
public average ( callable | string | null $callback = null ) : mixed
$callback callable | string | null
Результат mixed

avg() публичный метод

Get the average value of a given key.
public avg ( callable | string | null $callback = null ) : mixed
$callback callable | string | null
Результат mixed

chunk() публичный метод

Chunk the underlying collection array.
public chunk ( integer $size ) : static
$size integer
Результат static

collapse() публичный метод

Collapse the collection of items into a single array.
public collapse ( ) : static
Результат static

combine() публичный метод

Create a collection by using this collection for keys and another for its values.
public combine ( mixed $values ) : static
$values mixed
Результат static

contains() публичный метод

Determine if an item exists in the collection.
public contains ( mixed $key, mixed $value = null ) : boolean
$key mixed
$value mixed
Результат boolean

containsStrict() публичный метод

Determine if an item exists in the collection using strict comparison.
public containsStrict ( mixed $key, mixed $value = null ) : boolean
$key mixed
$value mixed
Результат boolean

count() публичный метод

Count the number of items in the collection.
public count ( ) : integer
Результат integer

diff() публичный метод

Get the items in the collection that are not present in the given items.
public diff ( mixed $items ) : static
$items mixed
Результат static

diffKeys() публичный метод

Get the items in the collection whose keys are not present in the given items.
public diffKeys ( mixed $items ) : static
$items mixed
Результат static

each() публичный метод

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

every() публичный метод

Create a new collection consisting of every n-th element.
public every ( integer $step, integer $offset ) : static
$step integer
$offset integer
Результат static

except() публичный метод

Get all items except for those with the specified keys.
public except ( mixed $keys ) : static
$keys mixed
Результат static

filter() публичный метод

Run a filter over each of the items.
public filter ( callable $callback = null ) : static
$callback callable
Результат static

first() публичный метод

Get the first item from the collection.
public first ( callable $callback = null, mixed $default = null ) : mixed
$callback callable
$default mixed
Результат mixed

flatMap() публичный метод

Map a collection and flatten the result by a single level.
public flatMap ( callable $callback ) : static
$callback callable
Результат static

flatten() публичный метод

Get a flattened array of the items in the collection.
public flatten ( integer $depth = INF ) : static
$depth integer
Результат static

flip() публичный метод

Flip the items in the collection.
public flip ( ) : static
Результат static

forPage() публичный метод

"Paginate" the collection by slicing it into a smaller collection.
public forPage ( integer $page, integer $perPage ) : static
$page integer
$perPage integer
Результат static

forget() публичный метод

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

get() публичный метод

Get an item from the collection by key.
public get ( mixed $key, mixed $default = null ) : mixed
$key mixed
$default mixed
Результат mixed

getArrayableItems() защищенный метод

Results array of items from Collection or Arrayable.
protected getArrayableItems ( mixed $items ) : array
$items mixed
Результат array

getCachingIterator() публичный метод

Get a CachingIterator instance.
public getCachingIterator ( integer $flags = CachingIterator::CALL_TOSTRING ) : CachingIterator
$flags integer
Результат CachingIterator

getIterator() публичный метод

Get an iterator for the items.
public getIterator ( ) : ArrayIterator
Результат ArrayIterator

groupBy() публичный метод

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
Результат static

has() публичный метод

Determine if an item exists in the collection by key.
public has ( mixed $key ) : boolean
$key mixed
Результат boolean

implode() публичный метод

Concatenate values of a given key as a string.
public implode ( string $value, string $glue = null ) : string
$value string
$glue string
Результат string

intersect() публичный метод

Intersect the collection with the given items.
public intersect ( mixed $items ) : static
$items mixed
Результат static

isEmpty() публичный метод

Determine if the collection is empty or not.
public isEmpty ( ) : boolean
Результат boolean

jsonSerialize() публичный метод

Convert the object into something JSON serializable.
public jsonSerialize ( ) : array
Результат array

keyBy() публичный метод

Key an associative array by a field or using a callback.
public keyBy ( callable | string $keyBy ) : static
$keyBy callable | string
Результат static

keys() публичный метод

Get the keys of the collection items.
public keys ( ) : static
Результат static

last() публичный метод

Get the last item from the collection.
public last ( callable $callback = null, mixed $default = null ) : mixed
$callback callable
$default mixed
Результат mixed

make() публичный статический метод

Create a new collection instance if the value isn't one already.
public static make ( mixed $items = [] ) : static
$items mixed
Результат static

map() публичный метод

Run a map over each of the items.
public map ( callable $callback ) : static
$callback callable
Результат static

mapWithKeys() публичный метод

The callback should return an associative array with a single key/value pair.
public mapWithKeys ( callable $callback ) : static
$callback callable
Результат static

max() публичный метод

Get the max value of a given key.
public max ( callable | string | null $callback = null ) : mixed
$callback callable | string | null
Результат mixed

median() публичный метод

Get the median of a given key.
public median ( null $key = null ) : mixed | null
$key null
Результат mixed | null

merge() публичный метод

Merge the collection with the given items.
public merge ( mixed $items ) : static
$items mixed
Результат static

min() публичный метод

Get the min value of a given key.
public min ( callable | string | null $callback = null ) : mixed
$callback callable | string | null
Результат mixed

mode() публичный метод

Get the mode of a given key.
public mode ( null $key = null ) : array
$key null
Результат array

offsetExists() публичный метод

Determine if an item exists at an offset.
public offsetExists ( mixed $key ) : boolean
$key mixed
Результат boolean

offsetGet() публичный метод

Get an item at a given offset.
public offsetGet ( mixed $key ) : mixed
$key mixed
Результат mixed

offsetSet() публичный метод

Set the item at a given offset.
public offsetSet ( mixed $key, mixed $value ) : void
$key mixed
$value mixed
Результат void

offsetUnset() публичный метод

Unset the item at a given offset.
public offsetUnset ( string $key ) : void
$key string
Результат void

only() публичный метод

Get the items with the specified keys.
public only ( mixed $keys ) : static
$keys mixed
Результат static

operatorForWhere() защищенный метод

Get an operator checker callback.
protected operatorForWhere ( string $key, string $operator, mixed $value ) : Closure
$key string
$operator string
$value mixed
Результат Closure

pipe() публичный метод

Pass the collection to the given callback and return the result.
public pipe ( callable $callback ) : mixed
$callback callable
Результат mixed

pluck() публичный метод

Get the values of a given key.
public pluck ( string $value, string | null $key = null ) : static
$value string
$key string | null
Результат static

pop() публичный метод

Get and remove the last item from the collection.
public pop ( ) : mixed
Результат mixed

prepend() публичный метод

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

pull() публичный метод

Get and remove an item from the collection.
public pull ( mixed $key, mixed $default = null ) : mixed
$key mixed
$default mixed
Результат mixed

push() публичный метод

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

put() публичный метод

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

random() публичный метод

Get one or more items randomly from the collection.
public random ( integer $amount = 1 ) : mixed
$amount integer
Результат mixed

reduce() публичный метод

Reduce the collection to a single value.
public reduce ( callable $callback, mixed $initial = null ) : mixed
$callback callable
$initial mixed
Результат mixed

reject() публичный метод

Create a collection of all elements that do not pass a given truth test.
public reject ( callable | mixed $callback ) : static
$callback callable | mixed
Результат static

reverse() публичный метод

Reverse items order.
public reverse ( ) : static
Результат static

shift() публичный метод

Get and remove the first item from the collection.
public shift ( ) : mixed
Результат mixed

shuffle() публичный метод

Shuffle the items in the collection.
public shuffle ( integer $seed = null ) : static
$seed integer
Результат static

slice() публичный метод

Slice the underlying collection array.
public slice ( integer $offset, integer $length = null ) : static
$offset integer
$length integer
Результат static

sort() публичный метод

Sort through each item with a callback.
public sort ( callable $callback = null ) : static
$callback callable
Результат static

sortBy() публичный метод

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
Результат static

sortByDesc() публичный метод

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
Результат static

splice() публичный метод

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
Результат static

split() публичный метод

Split a collection into a certain number of groups.
public split ( integer $numberOfGroups ) : static
$numberOfGroups integer
Результат static

sum() публичный метод

Get the sum of the given values.
public sum ( callable | string | null $callback = null ) : mixed
$callback callable | string | null
Результат mixed

take() публичный метод

Take the first or last {$limit} items.
public take ( integer $limit ) : static
$limit integer
Результат static

toArray() публичный метод

Get the collection of items as a plain array.
public toArray ( ) : array
Результат array

toBase() публичный метод

Get a base Support collection instance from this collection.
public toBase ( ) : Collection
Результат Collection

toJson() публичный метод

Get the collection of items as JSON.
public toJson ( integer $options ) : string
$options integer
Результат string

transform() публичный метод

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

union() публичный метод

Union the collection with the given items.
public union ( mixed $items ) : static
$items mixed
Результат static

unique() публичный метод

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
Результат static

uniqueStrict() публичный метод

Return only unique items from the collection array using strict comparison.
public uniqueStrict ( string | callable | null $key = null ) : static
$key string | callable | null
Результат static

useAsCallable() защищенный метод

Determine if the given value is callable, but not a string.
protected useAsCallable ( mixed $value ) : boolean
$value mixed
Результат boolean

valueRetriever() защищенный метод

Get a value retrieving callback.
protected valueRetriever ( string $value ) : callable
$value string
Результат callable

values() публичный метод

Reset the keys on the underlying array.
public values ( ) : static
Результат static

where() публичный метод

Filter items by the given key value pair.
public where ( string $key, mixed $operator, mixed $value = null ) : static
$key string
$operator mixed
$value mixed
Результат static

whereIn() публичный метод

Filter items by the given key value pair.
public whereIn ( string $key, mixed $values, boolean $strict = false ) : static
$key string
$values mixed
$strict boolean
Результат static

whereInStrict() публичный метод

Filter items by the given key value pair using strict comparison.
public whereInStrict ( string $key, mixed $values ) : static
$key string
$values mixed
Результат static

whereStrict() публичный метод

Filter items by the given key value pair using strict comparison.
public whereStrict ( string $key, mixed $value ) : static
$key string
$value mixed
Результат static

zip() публичный метод

e.g. new Collection([1, 2, 3])->zip([4, 5, 6]); => [[1, 4], [2, 5], [3, 6]]
public zip ( $items ) : static
$items
Результат static

Описание свойств

$items защищенное свойство

The items contained in the collection.
protected array $items
Результат array