Collection
in package
implements
Iterator
Create an iterable collection
Tags
Table of Contents
Interfaces
- Iterator
Methods
- __construct() : mixed
- Constructor method
- addObject() : mixed
- Add object to the collection
- addObjectAtPosition() : mixed
- Add object to the collection at a specified position
- addObjects() : mixed
- Add objects to the collection
- count() : int
- Get the item count.
- current() : mixed
- Get the current item from the collection.
- end() : mixed
- Set the internal pointer of the collection to the last item and return it.
- getFirst() : mixed
- Get first element in collection
- getLast() : mixed
- Get last element in collection
- inCollection() : mixed
- Check if an object is in the collection
- isFirst() : bool
- Check if the pointer is at the first record.
- isLast() : bool
- Check if the pointer is at the last record.
- key() : mixed
- Get the current position of the pointer.
- merge() : mixed
- Merge a collection with this collection.
- next() : mixed
- Place the pointer one item forward and return the item.
- previous() : mixed
- Place the pointer one item back and return the item.
- random() : mixed
- Pick a random child element
- randomize() : mixed
- Randomize the collection
- rebuild() : mixed
- Rebuild the collection index.
- remove() : bool
- Remove an element from the collection
- removeRecursive() : mixed
- Same as `remove()` but this is executed recursively.
- reverse() : Collection
- Reverse the order of the collection and return it.
- rewind() : Collection
- Reset the internal pointer of the collection to the first item.
- seek() : mixed
- Advance internal pointer to a specific index
- valid() : bool
- Test if the requested item is valid.
Methods
__construct()
Constructor method
public
__construct([array<string|int, mixed> $initArray = array() ]) : mixed
Parameters
- $initArray : array<string|int, mixed> = array()
-
An array of items to initialize the collection with.
addObject()
Add object to the collection
public
addObject(object $value[, bool $blnAddToBeginning = false ]) : mixed
Parameters
- $value : object
-
The object
- $blnAddToBeginning : bool = false
-
Add object to beginning of array or not
addObjectAtPosition()
Add object to the collection at a specified position
public
addObjectAtPosition(object $value, int $intPosition) : mixed
Parameters
- $value : object
-
The object
- $intPosition : int
-
The position the object should be placed at.
addObjects()
Add objects to the collection
public
addObjects(array<string|int, mixed> $arrObjects[, bool $blnAddToBeginning = false ]) : mixed
Parameters
- $arrObjects : array<string|int, mixed>
-
An array of items / collection of objects to be added
- $blnAddToBeginning : bool = false
-
Add objects to beginning of array or not
count()
Get the item count.
public
count() : int
Return values
int —The length of the collection
current()
Get the current item from the collection.
public
current() : mixed
Return values
mixed —The current item
end()
Set the internal pointer of the collection to the last item and return it.
public
end() : mixed
Return values
mixed —The last item in the collection
getFirst()
Get first element in collection
public
getFirst() : mixed
Return values
mixed —Returns first element in collection, null if collection is empty
getLast()
Get last element in collection
public
getLast([string $strType = "" ]) : mixed
Parameters
- $strType : string = ""
-
Optional type to search for. For example, you can search the Collection for the last Hidden element by doing:
$objCollection->getLast("\\ValidFormBuilder\\Hidden").
Return values
mixed —Returns last element in collection, null if collection is empty
inCollection()
Check if an object is in the collection
public
inCollection(mixed $varValue[, bool $blnReturnKey = false ]) : mixed
Parameters
- $varValue : mixed
-
Value to search for
- $blnReturnKey : bool = false
-
If true, returns the position of the item if found. Default: false.
isFirst()
Check if the pointer is at the first record.
public
isFirst() : bool
Return values
bool —True if current item is first item
isLast()
Check if the pointer is at the last record.
public
isLast() : bool
Return values
bool —True if current item is last item
key()
Get the current position of the pointer.
public
key() : mixed
Return values
mixed —The key function simply returns the
key of the array element that's currently being pointed to by the internal pointer. It does not move the
pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty,
key returns null.
merge()
Merge a collection with this collection.
public
merge(Collection $collection) : mixed
Parameters
- $collection : Collection
-
Collection to merge with
next()
Place the pointer one item forward and return the item.
public
next() : mixed
Attributes
- #[ReturnTypeWillChange]
Return values
mixed —The next item
previous()
Place the pointer one item back and return the item.
public
previous() : mixed
Return values
mixed —The previous item
random()
Pick a random child element
public
random() : mixed
Return values
mixed —Randomly selected item from collection
randomize()
Randomize the collection
public
randomize() : mixed
rebuild()
Rebuild the collection index.
public
rebuild() : mixed
remove()
Remove an element from the collection
public
remove(object $objElement) : bool
Parameters
- $objElement : object
-
The element that will be removed
Return values
bool —Always returns true. If it couldn't be found, its gone. If the element is found, it will be removed.
removeRecursive()
Same as `remove()` but this is executed recursively.
public
removeRecursive(Base $objElement) : mixed
Parameters
- $objElement : Base
Tags
reverse()
Reverse the order of the collection and return it.
public
reverse() : Collection
Return values
Collection —Returns itself after the internal collection is reversed.
rewind()
Reset the internal pointer of the collection to the first item.
public
rewind() : Collection
Attributes
- #[ReturnTypeWillChange]
Return values
Collection —Returns itself after the internal pointer is reset.
seek()
Advance internal pointer to a specific index
public
seek(int $intPosition) : mixed
Parameters
- $intPosition : int
-
The index to advance to
valid()
Test if the requested item is valid.
public
valid() : bool
Return values
bool —True if its valid, false if not.