MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
Referência ao interface Collection
Diagrama de heranças da classe Collection
ArrayCollection

Membros públicos

 add ($element)
 
 clear ()
 
 contains ($element)
 
 isEmpty ()
 
 remove ($key)
 
 removeElement ($element)
 
 containsKey ($key)
 
 get ($key)
 
 getKeys ()
 
 getValues ()
 
 set ($key, $value)
 
 toArray ()
 
 first ()
 
 last ()
 
 key ()
 
 current ()
 
 next ()
 
 exists (Closure $p)
 
 filter (Closure $p)
 
 forAll (Closure $p)
 
 map (Closure $func)
 
 partition (Closure $p)
 
 indexOf ($element)
 
 slice ($offset, $length=null)
 

Descrição detalhada

The missing (SPL) Collection/Array/OrderedMap interface.

A Collection resembles the nature of a regular PHP array. That is, it is essentially an ordered map that can also be used like a list.

A Collection has an internal iterator just like a PHP array. In addition, a Collection can be iterated with external iterators, which is preferrable. To use an external iterator simply use the foreach language construct to iterate over the collection (which calls getIterator() internally) or explicitly retrieve an iterator though getIterator() which can then be used to iterate over the collection. You can not rely on the internal iterator of the collection being at a certain position unless you explicitly positioned it before. Prefer iteration with external iterators.

Desde
2.0
Autor
Guilherme Blanco guilh.nosp@m.erme.nosp@m.blanc.nosp@m.o@ho.nosp@m.tmail.nosp@m..com
Jonathan Wage jonwa.nosp@m.ge@g.nosp@m.mail..nosp@m.com
Roman Borschel roman.nosp@m.@cod.nosp@m.e-fac.nosp@m.tory.nosp@m..org

Definido na linha 46 do ficheiro Collection.php.

Documentação das funções

◆ add()

add ( $element)

Adds an element at the end of the collection.

Parâmetros
mixed$elementThe element to add.
Retorna
boolean Always TRUE.

Implementado em ArrayCollection.

◆ clear()

clear ( )

Clears the collection, removing all elements.

Implementado em ArrayCollection.

◆ contains()

contains ( $element)

Checks whether an element is contained in the collection. This is an O(n) operation, where n is the size of the collection.

Parâmetros
mixed$elementThe element to search for.
Retorna
boolean TRUE if the collection contains the element, FALSE otherwise.

Implementado em ArrayCollection.

◆ containsKey()

containsKey ( $key)

Checks whether the collection contains an element with the specified key/index.

Parâmetros
string | integer$keyThe key/index to check for.
Retorna
boolean TRUE if the collection contains an element with the specified key/index, FALSE otherwise.

Implementado em ArrayCollection.

◆ current()

current ( )

Gets the element of the collection at the current iterator position.

Implementado em ArrayCollection.

◆ exists()

exists ( Closure $p)

Tests for the existence of an element that satisfies the given predicate.

Parâmetros
Closure$pThe predicate.
Retorna
boolean TRUE if the predicate is TRUE for at least one element, FALSE otherwise.

Implementado em ArrayCollection.

◆ filter()

filter ( Closure $p)

Returns all the elements of this collection that satisfy the predicate p. The order of the elements is preserved.

Parâmetros
Closure$pThe predicate used for filtering.
Retorna
Collection A collection with the results of the filter operation.

Implementado em ArrayCollection.

◆ first()

first ( )

Sets the internal iterator to the first element in the collection and returns this element.

Retorna
mixed

Implementado em ArrayCollection.

◆ forAll()

forAll ( Closure $p)

Applies the given predicate p to all elements of this collection, returning true, if the predicate yields true for all elements.

Parâmetros
Closure$pThe predicate.
Retorna
boolean TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.

Implementado em ArrayCollection.

◆ get()

get ( $key)

Gets the element at the specified key/index.

Parâmetros
string | integer$keyThe key/index of the element to retrieve.
Retorna
mixed

Implementado em ArrayCollection.

◆ getKeys()

getKeys ( )

Gets all keys/indices of the collection.

Retorna
array The keys/indices of the collection, in the order of the corresponding elements in the collection.

Implementado em ArrayCollection.

◆ getValues()

getValues ( )

Gets all values of the collection.

Retorna
array The values of all elements in the collection, in the order they appear in the collection.

Implementado em ArrayCollection.

◆ indexOf()

indexOf ( $element)

Gets the index/key of a given element. The comparison of two elements is strict, that means not only the value but also the type must match. For objects this means reference equality.

Parâmetros
mixed$elementThe element to search for.
Retorna
mixed The key/index of the element or FALSE if the element was not found.

Implementado em ArrayCollection.

◆ isEmpty()

isEmpty ( )

Checks whether the collection is empty (contains no elements).

Retorna
boolean TRUE if the collection is empty, FALSE otherwise.

Implementado em ArrayCollection.

◆ key()

key ( )

Gets the key/index of the element at the current iterator position.

Implementado em ArrayCollection.

◆ last()

last ( )

Sets the internal iterator to the last element in the collection and returns this element.

Retorna
mixed

Implementado em ArrayCollection.

◆ map()

map ( Closure $func)

Applies the given function to each element in the collection and returns a new collection with the elements returned by the function.

Parâmetros
Closure$func
Retorna
Collection

Implementado em ArrayCollection.

◆ next()

next ( )

Moves the internal iterator position to the next element.

Implementado em ArrayCollection.

◆ partition()

partition ( Closure $p)

Partitions this collection in two collections according to a predicate. Keys are preserved in the resulting collections.

Parâmetros
Closure$pThe predicate on which to partition.
Retorna
array An array with two elements. The first element contains the collection of elements where the predicate returned TRUE, the second element contains the collection of elements where the predicate returned FALSE.

Implementado em ArrayCollection.

◆ remove()

remove ( $key)

Removes the element at the specified index from the collection.

Parâmetros
string | integer$keyThe kex/index of the element to remove.
Retorna
mixed The removed element or NULL, if the collection did not contain the element.

Implementado em ArrayCollection.

◆ removeElement()

removeElement ( $element)

Removes the specified element from the collection, if it is found.

Parâmetros
mixed$elementThe element to remove.
Retorna
boolean TRUE if this collection contained the specified element, FALSE otherwise.

Implementado em ArrayCollection.

◆ set()

set ( $key,
$value )

Sets an element in the collection at the specified key/index.

Parâmetros
string | integer$keyThe key/index of the element to set.
mixed$valueThe element to set.

Implementado em ArrayCollection.

◆ slice()

slice ( $offset,
$length = null )

Extract a slice of $length elements starting at position $offset from the Collection.

If $length is null it returns all elements from $offset to the end of the Collection. Keys have to be preserved by this method. Calling this method will only return the selected slice and NOT change the elements contained in the collection slice is called on.

Parâmetros
int$offset
int$length
Retorna
array

Implementado em ArrayCollection.

◆ toArray()

toArray ( )

Gets a native PHP array representation of the collection.

Retorna
array

Implementado em ArrayCollection.


A documentação para este interface foi gerada a partir do seguinte ficheiro: