PHP 클래스 Illuminate\Support\Collection

상속: implements ArrayAcces\ArrayAccess, implements Illuminate\Support\Contracts\ArrayableInterface, implements Countabl\Countable, implements IteratorAggregat\IteratorAggregate, implements Illuminate\Support\Contracts\JsonableInterface
파일 보기 프로젝트 열기: tightenco/collect 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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.

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