List Library
IgnitedCMS ships with a variety of useful List, array helper utilities
Basic setup is explained below, the lst library supports basic FIFO list operations.
$this->load->library('lst');
Function reference
Parameters:
array - an array of object to initialise lst class
Returns:
void
Return type:
void
$this->lst->set([1, 2, 3, 4, 'test']);
Function reference
Parameters:
none - dumps array as string
Returns:
void
Return type:
void
$this->lst->set([1, 2, 3, 4, 'test'])->print(); (Echo array object to view as associative array)
Function reference
Parameters:
String, int, float - push this value to the lst object at the end
Returns:
void
Return type:
void
$this->lst->set([1, 2, 3, 4, 'test'])->push('a')->push(8)->print();
Function reference
Parameters:
none - pops the very last element in the list out of the stack
Returns:
void
Return type:
void
$this->lst->set([1, 2, 3, 4, 'test'])->pop()->print(); (Echos array except with 'test' the last element - removed)
Function reference
Parameters:
string, int, float - checks to see if list object contains variable
Returns:
bool - true or false
Return type:
bool
$tmp = $this->lst->set([1, 2, 3, 4, 'test'])->contains('test'); (Returns true)
Function reference
Parameters:
none - removes all duplicate elements from array
Returns:
void
Return type:
void
$this->lst->set([1, 2, 3, 4, 2, 1)->unique()->print(); (Echos '1,2,3,4' as the other values are duplicates)
Function reference
Parameters:
none - returns length of current array object
Returns:
void
Return type:
void
$len = $this->lst->set([1, 2, 3, 4])->length(); echo $len; (Echos '4' to the view)
Function reference
Parameters:
string $key - sorts assoc array by key value
Returns:
void
Return type:
void
$this->lst->set([]); $this->lst->push(['name' => 'zoey', 'age' => '2']); $this->lst->push(['name' => 'amy', 'age' => '18']); $this->lst->print(); echo br(); echo 'sorted'; $this->lst->sort('name')->print();
Sorts by key in ASCENDING order
Function reference
Parameters:
none - converts assoc array into valid JSON string
Returns:
void
Return type:
void
$block = $this->lst->set([]); $block->push(['name' => 'zoey', 'age' => '2']); $block->push(['name' => 'amy', 'age' => '18']); echo $block->to_json();
Function reference
Parameters:
int $start, int $end, string (odd or even - optional)
Returns:
void
Return type:
void
Special engine function to quickly generate for iterations like 1..20
$block = $this->lst->for(1,10); print_r($block); (Echos 1,2,3,4,5,6,7,8,9,10) Note you can pass an optional 'odd' or 'even' flag here