PHP Class Prado\Collections\TStack

TStack implements a stack. The typical stack operations are implemented, which include {@link push()}, {@link pop()} and {@link peek()}. In addition, {@link contains()} can be used to check if an item is contained in the stack. To obtain the number of the items in the stack, check the {@link getCount Count} property. Items in the stack may be traversed using foreach as follows, foreach($stack as $item) ...
Since: 3.0
Author: Qiang Xue ([email protected])
Inheritance: extends Prado\TComponent, implements IteratorAggregate, implements Countable
Exibir arquivo Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
__construct ( $data = null ) Constructor.
clear ( ) Removes all items in the stack.
contains ( $item ) : boolean
copyFrom ( $data ) Copies iterable data into the stack.
count ( ) : integer Returns the number of items in the stack.
getCount ( ) : integer
getIterator ( ) : Iterator Returns an iterator for traversing the items in the stack.
peek ( ) : mixed Returns the item at the top of the stack.
pop ( ) : mixed Pops up the item at the top of the stack.
push ( $item ) Pushes an item into the stack.
toArray ( ) : array

Method Details

__construct() public method

Initializes the stack with an array or an iterable object.
public __construct ( $data = null )

clear() public method

Removes all items in the stack.
public clear ( )

contains() public method

public contains ( $item ) : boolean
return boolean whether the stack contains the item

copyFrom() public method

Note, existing data in the list will be cleared first.
public copyFrom ( $data )

count() public method

This method is required by \Countable interface.
public count ( ) : integer
return integer number of items in the stack.

getCount() public method

public getCount ( ) : integer
return integer the number of items in the stack

getIterator() public method

This method is required by the interface \IteratorAggregate.
public getIterator ( ) : Iterator
return Iterator an iterator for traversing the items in the stack.

peek() public method

Unlike {@link pop()}, this method does not remove the item from the stack.
public peek ( ) : mixed
return mixed item at the top of the stack

pop() public method

Pops up the item at the top of the stack.
public pop ( ) : mixed
return mixed the item at the top of the stack

push() public method

Pushes an item into the stack.
public push ( $item )

toArray() public method

public toArray ( ) : array
return array the list of items in stack