interface Illuminate / Support / Enumerable
You are viewing an older version of the documentation. For the latest, please visit master documentation.

Enumerable

Methods

public static

make ( $items ) : static

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

Parameters

  • $items mixed
public static

times ( $number , callable $callback ) : static

Create a new instance by invoking the callback a given amount of times.

Parameters

  • $number int
  • $callback callable|null
public static

range ( $from , $to ) : static

Create a collection with the given range.

Parameters

  • $from int
  • $to int
public static

wrap ( $value ) : static

Wrap the given value in a collection if applicable.

Parameters

  • $value mixed
public static

unwrap ( $value ) : array

Get the underlying items from the given collection if applicable.

Parameters

  • $value array|static
public static

empty ( ) : static

Create a new instance with no items.

public

all ( ) : array

Get all items in the enumerable.

public

average ( $callback ) : mixed

Alias for the "avg" method.

Parameters

  • $callback callable|string|null
public

median ( $key ) : mixed

Get the median of a given key.

Parameters

  • $key string|array|null
public

mode ( $key ) : array|null

Get the mode of a given key.

Parameters

  • $key string|array|null
public

collapse ( ) : static

Collapse the items into a single enumerable.

public

some ( $key , $operator , $value ) : bool

Alias for the "contains" method.

Parameters

  • $key mixed
  • $operator mixed
  • $value mixed
public

containsStrict ( $key , $value ) : bool

Determine if an item exists, using strict comparison.

Parameters

  • $key mixed
  • $value mixed
public

avg ( $callback ) : mixed

Get the average value of a given key.

Parameters

  • $callback callable|string|null
public

contains ( $key , $operator , $value ) : bool

Determine if an item exists in the enumerable.

Parameters

  • $key mixed
  • $operator mixed
  • $value mixed
public

crossJoin ( $lists ) : static

Cross join with the given lists, returning all possible permutations.

Parameters

  • $lists mixed
public

dd ( $args ) : void

Dump the collection and end the script.

Parameters

  • $args mixed
public

dump ( ) : $this

Dump the collection.

public

diff ( $items ) : static

Get the items that are not present in the given items.

Parameters

  • $items mixed
public

diffUsing ( $items , callable $callback ) : static

Get the items that are not present in the given items, using the callback.

Parameters

  • $items mixed
  • $callback callable
public

diffAssoc ( $items ) : static

Get the items whose keys and values are not present in the given items.

Parameters

  • $items mixed
public

diffAssocUsing ( $items , callable $callback ) : static

Get the items whose keys and values are not present in the given items, using the callback.

Parameters

  • $items mixed
  • $callback callable
public

diffKeys ( $items ) : static

Get the items whose keys are not present in the given items.

Parameters

  • $items mixed
public

diffKeysUsing ( $items , callable $callback ) : static

Get the items whose keys are not present in the given items, using the callback.

Parameters

  • $items mixed
  • $callback callable
public

duplicates ( $callback , $strict ) : static

Retrieve duplicate items.

Parameters

  • $callback callable|string|null
  • $strict bool
public

duplicatesStrict ( $callback ) : static

Retrieve duplicate items using strict comparison.

Parameters

  • $callback callable|string|null
public

each ( callable $callback ) : $this

Execute a callback over each item.

Parameters

  • $callback callable
public

eachSpread ( callable $callback ) : static

Execute a callback over each nested chunk of items.

Parameters

  • $callback callable
public

every ( $key , $operator , $value ) : bool

Determine if all items pass the given truth test.

Parameters

  • $key string|callable
  • $operator mixed
  • $value mixed
public

except ( $keys ) : static

Get all items except for those with the specified keys.

Parameters

  • $keys mixed
public

filter ( callable $callback ) : static

Run a filter over each of the items.

Parameters

  • $callback callable|null
public

when ( $value , callable $callback , callable $default ) : static|mixed

Apply the callback if the value is truthy.

Parameters

  • $value bool
  • $callback callable
  • $default callable|null
public

whenEmpty ( callable $callback , callable $default ) : static|mixed

Apply the callback if the collection is empty.

Parameters

  • $callback callable
  • $default callable|null
public

whenNotEmpty ( callable $callback , callable $default ) : static|mixed

Apply the callback if the collection is not empty.

Parameters

  • $callback callable
  • $default callable|null
public

unless ( $value , callable $callback , callable $default ) : static|mixed

Apply the callback if the value is falsy.

Parameters

  • $value bool
  • $callback callable
  • $default callable|null
public

unlessEmpty ( callable $callback , callable $default ) : static|mixed

Apply the callback unless the collection is empty.

Parameters

  • $callback callable
  • $default callable|null
public

unlessNotEmpty ( callable $callback , callable $default ) : static|mixed

Apply the callback unless the collection is not empty.

Parameters

  • $callback callable
  • $default callable|null
public

where ( $key , $operator , $value ) : static

Filter items by the given key value pair.

Parameters

  • $key string
  • $operator mixed
  • $value mixed
public

whereNull ( $key ) : static

Filter items where the value for the given key is null.

Parameters

  • $key string|null
public

whereNotNull ( $key ) : static

Filter items where the value for the given key is not null.

Parameters

  • $key string|null
public

whereStrict ( $key , $value ) : static

Filter items by the given key value pair using strict comparison.

Parameters

  • $key string
  • $value mixed
public

whereIn ( $key , $values , $strict ) : static

Filter items by the given key value pair.

Parameters

  • $key string
  • $values mixed
  • $strict bool
public

whereInStrict ( $key , $values ) : static

Filter items by the given key value pair using strict comparison.

Parameters

  • $key string
  • $values mixed
public

whereBetween ( $key , $values ) : static

Filter items such that the value of the given key is between the given values.

Parameters

  • $key string
  • $values array
public

whereNotBetween ( $key , $values ) : static

Filter items such that the value of the given key is not between the given values.

Parameters

  • $key string
  • $values array
public

whereNotIn ( $key , $values , $strict ) : static

Filter items by the given key value pair.

Parameters

  • $key string
  • $values mixed
  • $strict bool
public

whereNotInStrict ( $key , $values ) : static

Filter items by the given key value pair using strict comparison.

Parameters

  • $key string
  • $values mixed
public

whereInstanceOf ( $type ) : static

Filter the items, removing any items that don't match the given type(s).

Parameters

  • $type string|string[]
public

first ( callable $callback , $default ) : mixed

Get the first item from the enumerable passing the given truth test.

Parameters

  • $callback callable|null
  • $default mixed
public

firstWhere ( $key , $operator , $value ) : mixed

Get the first item by the given key value pair.

Parameters

  • $key string
  • $operator mixed
  • $value mixed
public

flatten ( $depth ) : static

Get a flattened array of the items in the collection.

Parameters

  • $depth int
public

flip ( ) : static

Flip the values with their keys.

public

get ( $key , $default ) : mixed

Get an item from the collection by key.

Parameters

  • $key mixed
  • $default mixed
public

groupBy ( $groupBy , $preserveKeys ) : static

Group an associative array by a field or using a callback.

Parameters

  • $groupBy array|callable|string
  • $preserveKeys bool
public

keyBy ( $keyBy ) : static

Key an associative array by a field or using a callback.

Parameters

  • $keyBy callable|string
public

has ( $key ) : bool

Determine if an item exists in the collection by key.

Parameters

  • $key mixed
public

implode ( $value , $glue ) : string

Concatenate values of a given key as a string.

Parameters

  • $value string
  • $glue string|null
public

intersect ( $items ) : static

Intersect the collection with the given items.

Parameters

  • $items mixed
public

intersectByKeys ( $items ) : static

Intersect the collection with the given items by key.

Parameters

  • $items mixed
public

isEmpty ( ) : bool

Determine if the collection is empty or not.

public

isNotEmpty ( ) : bool

Determine if the collection is not empty.

public

join ( $glue , $finalGlue ) : string

Join all items from the collection using a string. The final items can use a separate glue string.

Parameters

  • $glue string
  • $finalGlue string
public

keys ( ) : static

Get the keys of the collection items.

public

last ( callable $callback , $default ) : mixed

Get the last item from the collection.

Parameters

  • $callback callable|null
  • $default mixed
public

map ( callable $callback ) : static

Run a map over each of the items.

Parameters

  • $callback callable
public

mapSpread ( callable $callback ) : static

Run a map over each nested chunk of items.

Parameters

  • $callback callable
public

mapToDictionary ( callable $callback ) : static

Run a dictionary map over the items.

Parameters

  • $callback callable
public

mapToGroups ( callable $callback ) : static

Run a grouping map over the items.

Parameters

  • $callback callable
public

mapWithKeys ( callable $callback ) : static

Run an associative map over each of the items.

Parameters

  • $callback callable
public

flatMap ( callable $callback ) : static

Map a collection and flatten the result by a single level.

Parameters

  • $callback callable
public

mapInto ( $class ) : static

Map the values into a new class.

Parameters

  • $class string
public

merge ( $items ) : static

Merge the collection with the given items.

Parameters

  • $items mixed
public

mergeRecursive ( $items ) : static

Recursively merge the collection with the given items.

Parameters

  • $items mixed
public

combine ( $values ) : static

Create a collection by using this collection for keys and another for its values.

Parameters

  • $values mixed
public

union ( $items ) : static

Union the collection with the given items.

Parameters

  • $items mixed
public

min ( $callback ) : mixed

Get the min value of a given key.

Parameters

  • $callback callable|string|null
public

max ( $callback ) : mixed

Get the max value of a given key.

Parameters

  • $callback callable|string|null
public

nth ( $step , $offset ) : static

Create a new collection consisting of every n-th element.

Parameters

  • $step int
  • $offset int
public

only ( $keys ) : static

Get the items with the specified keys.

Parameters

  • $keys mixed
public

forPage ( $page , $perPage ) : static

"Paginate" the collection by slicing it into a smaller collection.

Parameters

  • $page int
  • $perPage int
public

partition ( $key , $operator , $value ) : static

Partition the collection into two arrays using the given callback or key.

Parameters

  • $key callable|string
  • $operator mixed
  • $value mixed
public

concat ( $source ) : static

Push all of the given items onto the collection.

Parameters

  • $source iterable
public

random ( $number ) : static|mixed

Get one or a specified number of items randomly from the collection.

Parameters

  • $number int|null
public

reduce ( callable $callback , $initial ) : mixed

Reduce the collection to a single value.

Parameters

  • $callback callable
  • $initial mixed
public

replace ( $items ) : static

Replace the collection items with the given items.

Parameters

  • $items mixed
public

replaceRecursive ( $items ) : static

Recursively replace the collection items with the given items.

Parameters

  • $items mixed
public

reverse ( ) : static

Reverse items order.

public

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

Parameters

  • $value mixed
  • $strict bool
public

shuffle ( $seed ) : static

Shuffle the items in the collection.

Parameters

  • $seed int|null
public

skip ( $count ) : static

Skip the first {$count} items.

Parameters

  • $count int
public

skipUntil ( $value ) : static

Skip items in the collection until the given condition is met.

Parameters

  • $value mixed
public

skipWhile ( $value ) : static

Skip items in the collection while the given condition is met.

Parameters

  • $value mixed
public

slice ( $offset , $length ) : static

Get a slice of items from the enumerable.

Parameters

  • $offset int
  • $length int|null
public

split ( $numberOfGroups ) : static

Split a collection into a certain number of groups.

Parameters

  • $numberOfGroups int
public

chunk ( $size ) : static

Chunk the collection into chunks of the given size.

Parameters

  • $size int
public

chunkWhile ( callable $callback ) : static

Chunk the collection into chunks with a callback.

Parameters

  • $callback callable
public

sort ( $callback ) : static

Sort through each item with a callback.

Parameters

  • $callback callable|null|int
public

sortDesc ( $options ) : static

Sort items in descending order.

Parameters

  • $options int
public

sortBy ( $callback , $options , $descending ) : static

Sort the collection using the given callback.

Parameters

  • $callback callable|string
  • $options int
  • $descending bool
public

sortByDesc ( $callback , $options ) : static

Sort the collection in descending order using the given callback.

Parameters

  • $callback callable|string
  • $options int
public

sortKeys ( $options , $descending ) : static

Sort the collection keys.

Parameters

  • $options int
  • $descending bool
public

sortKeysDesc ( $options ) : static

Sort the collection keys in descending order.

Parameters

  • $options int
public

sum ( $callback ) : mixed

Get the sum of the given values.

Parameters

  • $callback callable|string|null
public

take ( $limit ) : static

Take the first or last {$limit} items.

Parameters

  • $limit int
public

takeUntil ( $value ) : static

Take items in the collection until the given condition is met.

Parameters

  • $value mixed
public

takeWhile ( $value ) : static

Take items in the collection while the given condition is met.

Parameters

  • $value mixed
public

tap ( callable $callback ) : $this

Pass the collection to the given callback and then return it.

Parameters

  • $callback callable
public

pipe ( callable $callback ) : mixed

Pass the enumerable to the given callback and return the result.

Parameters

  • $callback callable
public

pluck ( $value , $key ) : static

Get the values of a given key.

Parameters

  • $value string|array
  • $key string|null
public

reject ( $callback ) : static

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

Parameters

  • $callback callable|mixed
public

unique ( $key , $strict ) : static

Return only unique items from the collection array.

Parameters

  • $key string|callable|null
  • $strict bool
public

uniqueStrict ( $key ) : static

Return only unique items from the collection array using strict comparison.

Parameters

  • $key string|callable|null
public

values ( ) : static

Reset the keys on the underlying array.

public

pad ( $size , $value ) : static

Pad collection to the specified length with a value.

Parameters

  • $size int
  • $value mixed
public

countBy ( $callback ) : static

Count the number of items in the collection using a given truth test.

Parameters

  • $callback callable|null
public

zip ( $items ) : static

Zip the collection together with one or more arrays.

Parameters

  • $items mixed
public

collect ( ) : Collection

Collect the values into a collection.

public

__toString ( ) : string

Convert the collection to its string representation.

public static

proxy ( $method ) : void

Add a method to the list of proxied methods.

Parameters

  • $method string
public

__get ( $key ) : mixed

Dynamically access collection proxies.

Parameters

  • $key string