Skip to content
Michael Tils edited this page Mar 25, 2015 · 2 revisions

An OrderedList is a basic stack container to store sequences and append, insert and remove items.

The basic syntax to add items is:

use Collection\OrderedList;

$list = new OrderedList;
$list->append(2);
$list->append(3);
$list->push(4); // Does the same as append for more php-ish syntax

// Result: OrderedList[2,3,4]

You can also pass an array to the constructor or set it via setSrc() to fill the OrderedList. The indexes of your array will be lost.

use Collection\OrderedList;

$list = new OrderedList([2,3,4]);

// Result: OrderedList[2,3,4]

If you like to add more values to your OrderedList use extend($other).

use Collection\OrderedList;

$list = new OrderedList([2,3,4]);
// Result: OrderedList[2,3,4]

$list2 = new OrderedList([5,4,3]);
// Result: OrderedList[5,4,3]

$list->extend($list2); // extends $list by all values of $list2
// $list is now OrderedList[2,3,4,5,4,3]

To insert values use the insert($index,$item) method. The

Clone this wiki locally