ez.no / exponential / documentation / development / libraries / ez template / operators / array handling
These documentation pages are no longer maintained. Please visit the new documentation site.
[Some of this functionality already exsists, however most of it will appear in Exponential 3.2]
The array template class provides functionality for basic manipulation of arrays and strings. The table below contains a quick summary along with a short description of the currently available array/string operators. Some operators work both on arrays and strings, some don't (the A/S columns show this). Detailed description of each operator can be found under this overview. Click on the name of an operator to jump to the corresponding description within this page.
Short summary:
Builds an array using specified elements.
Usage:
array( mixed elements)
Full description:
Builds an array using specified elements (passed as parameters to the operator).
Example(s):
{array(1,2,3,4,5,6,7)}
returns the array (1,2,3,4,5,6,7).
Short summary:
Merges input array and all arrays passed as parameter into one array.
Usage:
$input_array|merge(array(s) merge_this_in)
Full description:
This operator will merge the input_array with all arrays passed as parameter (in merge_this_in) into one array.
Example(s):
{array(1,2)|merge(array(3,4),array(5,6,7))}
returns an array with integers 1 trough 7: (1,2,3,4,5,6,7).
Short summary:
Builds an associative array.
Usage:
hash( mixed elements)
Full description:
Builds an associative array using the
specified key/value pairs. Odd parameters are considered to be keys, and
even parameters are values.
Example(s):
{hash(1,'one',2,'two',3,'three'}
returns a hash corresponding to the PHP array array(1=>'one',2=>'two',3=>'three').
Short summary:
Removes duplicate values from an array.
Usage:
$input_array|unique( no parameters)
Full description:
Removes duplicate values from an array.
Example(s):
{array(1,2,2,3,4,4,5,6,7)|unique}
returns the following array: (1,2,3,4,5,6,7).
Short summary:
Calculates the sum of values in an array.
Usage:
$input_array|sum( no parameters)
Full description:
Calculates the sum of values in an array.
Example(s):
{array(1,2,3,4,5,6,7)|sum}
returns an integer with its value set to 28.
Short summary:
Joins array elements with a string.
Usage:
$input_array|implode(string separator);
Full description:
Returns a string containing a string
representation of all the array elements (from the inputted array) in
the same order, with the separator string between each element.
Example(s):
{array(1,2,3,4,5,6,7)|implode(',')}
returns the string "1,2,3,4,5,6,7".
{array(1,2,3,4,5,6,7)|implode("_-_")}
returns the string "1_-_2_-_3_-_4_-_5_-_6_-_7".
Short summary:
Splits a string into an array of substrings, or an array into an array of two subarrays.
Usage:
$input_string|explode(string separator])
$input_array|explode(integer offset])
Full description:
The explode operator will return an array of strings. Each element in the array will be a substring of the input_string formed by splitting it on boundaries defined by the separator string.
Explode will also accept an array as input. In that case, it will expect the parameter to be an integer offset specifying where to split the array in two. It will return an array containing the two resulting arrays.
Example(s):
{"Your-string-is-boring!"|explode("-")}
returns the following array of strings: ("Your","string","is","boring!").
{array('a','b','c','d','e')|explode(3)}
returns the following array: ( array('a','b','c'), array('d','e') ).
Short summary:
Extracts a portion from an array or a string.
Usage:
$input_array|extract(integer offset [,integer length])
$input_string|extract(integer offset [,integer length])
Full description:
The extract operator will return a portion of an inputted string or array. The returned portion is defined by the offset and length parameters. If length is omitted, the rest of the array/string (from offset) will be returned.
Example(s):
{array(1,2,3,4,5,6,7)|extract(2)}
returns the array (3,4,5,6,7).
{array(1,2,3,4,5,6,7)|extract(3,3)}
returns the array (4,5,6).
{"I love monday mornings!"|extract(6)}
returns the string "monday mornings!".
{"Big apples."|extract(4,5)}
returns the string "apple".
Short summary:
Extracts a portion from the start of an array or a string.
Usage:
$input_array|extract_left(integer length)
$input_string|extract_left(integer length)
Full description:
This operator extracts a portion from the start of an array or a string; the length parameter defines the length of the desired portion.
Example(s):
{array(1,2,3,4,5,6,7)|extract_left(3)}
returns the array (1,2,3).
{"Gooooood morning Vietnam!|extract_left(8)}
returns the string "Gooooood".
Short summary:
Extracts a portion from the end of an array or a string.
Usage:
$input_array|extract_right( length)
$input_string|extract_right( length)
Full description:
This operator extracts a portion from the end of an array or a string; the length parameter defines the length of the desired portion.
Example(s):
{array(1,2,3,4,5,6,7)|extract_right(3)}
returns the array (5,6,7).
{"Gooooood morning Vietnam!|extract_right(8)}
returns the string "Vietnam!".
Short summary:
Checks if array/string begins with a specific element/sequence.
Usage:
$input_array|begins_with(integer(s) match)
$input_string|begins_with(string match)
Full description:
The begins_with operator checks if the
inputted string or array begins with a specified
element/character/sequence (or not). Returns true or false.
Example(s):
{array(1,2,3,4,5,6,7)|begins_with(1,2,3)}
returns true.
{array(1,2,3,4,5,6,7)|begins_with(2,3,4)}
returns false.
{"Huge security hole discovered in Windoze 2015."|begins_with("Huge")}
returns true.
{"Huge security hole discovered in Windoze 2015."|begins_with("huge")}
returns false.
Short summary:
Checks if array/string ends with a specific element/sequence.
Usage:
$input_array|ends_with(integer(s) match)
$input_string|ends_with(string match)
Full description:
The ends_with operator checks if the
inputted string or array ends with a specified
element/character/sequence (or not). Returns true or false.
Example(s):
{array(1,2,3,4,5,6,7)|ends_with(5,6,7)}
returns true.
{array(1,2,3,4,5,6,7)|ends_with(4,5,6)}
returns false.
{"Linux is great!"|ends_with("great!")}
returns true.
{"Linux is great!"|begins_with("great")}
returns false.
Short summary:
Repeats the contents of an array or a string.
Usage:
$input_array|repeat(integer times)
$input_string|repeat(integer times)
Full description:
This operator returns a repeated version of an array or a string. The items parameter defines the number of times the array/string should be repeated.
Example(s):
{array(1,2,3,4)|repeat(3)}
returns the array (1,2,3,4,1,2,3,4,1,2,3,4).
{"*DJ Cat Show* "|repeat(2)}
returns the string "*DJ Cat Show* *DJ Cat Show* ".
Short summary:
Reverses the contents of an array or a string.
Usage:
$input_array|reverse( no parameters)
$input_string|reverse( no parameters)
Full description:
The reverse operator simply returns a reversed version of an inputted string or array.
Example(s):
{array(1,2,3,4)|reverse}
returns the array (4,3,2,1).
{"Do you yahoo?"|reverse}
returns the string "?oohay uoy oD".
Short summary:
Inserts an element/sequence at specified position in array/string.
Usage:
$input_array|insert(integer offset, elements_to_insert)
$input_string|insert(integer offset, string put_this_in)
Full description:
This operator inserts an element sequence of
elements/characters at a specified position in an array or a string.
Returns the original array/string with the inserted values.
Example(s):
{array(1,2,3,6,7)|insert(3,4,5)}
returns the array (1,2,3,4,5,6,7).
{"my string is simple"|insert(3,"static ")}
returns the string "my static string is simple".
Short summary:
Removes element(s) from array or string.
Usage:
$input_array|remove(integer offset, integer length)
$input_string|remove(integer offset, integer length)
Full description:
The remove operator simply removes element(s) from array or string (and returns the chopped version of the array/string). The offset parameter defines the start of the portion to be removed while the length prameter defines the length of the portion. Look at the examples.
Example(s):
{array(1,2,3,4,5,6,7)|remove(3,3)}
returns the array (1,2,3,7).
"my string is simple"|remove(3,2)
returns the string "my ring is simple".
Short summary:
Not implemented, yet.
Usage:
Not implemented, yet.
Full description:
Not implemented, yet.
Example(s):
{Not implemented, yet.}
returns: Not implemented, yet.
Short summary:
Appends element(s) to arrays and strings.
Usage:
$input_array|append( parameters)
$input_string|append(string string_to_append)
Full description:
Puts the parameter value(s) to the end of the input array/string.
Example(s):
{array(1,2,3)|append(4,5,6)}
returns tha array (1,2,3,4,5,6).
{"Sigourney "|append("Weaver")}
returns the string "Sigourney Weaver".
Short summary:
Prepends element(s) to arrays and strings.
Usage:
$input_array|prepend( parameters)
$input_string|prepend(string string_to_append)
Full description:
Adds the parameter value(s) at the start of the input array/string.
Example(s):
{array(4,5,6)|prepend(1,2,3)}
returns tha array (1,2,3,4,5,6).
{"Weaver"|prepend("Sigourney ")}
returns the string "Sigourney Weaver".
Short summary:
Compares the contents of two arrays or strings.
Usage:
$input_array|compare(array compare_with)
$input_string|compare(string compare_with)
Full description:
This operator simply compares the contents of two arrays or strings and returns true if they're the same, false if they differ.
Example(s):
{let myarray=array(1,2,3,4,5)} {let yourarray=array(1,2,3,4)} {$myarray|compare($yourarray)} {/let} {/let}
returns false.
{let myarray=array(1,2,3,4,5)} {let yourarray=array(1,2,3,4,5)} {$myarray|compare($yourarray)} {/let} {/let}
returns true.
{let mystring="asdf"} {let yourstring="asdf"} {$mystring|compare($yourstring)} {/let} {/let}
returns true.
{let mystring="asdf"} {let yourstring="asd"} {$mystring|compare($yourstring)} {/let} {/let}
returns false.
Short summary:
Checks if an array/string contains a specific element/sequence.
Usage:
$input_array|contains( match)
$input_string|contains( match)
Full description:
Checks if an array/string contains a specific element/sequence. If yes: returns true, if no: returns false.
Example(s):
{"mystring"|contains("my")}
returns true.
{"mystring"|contains("asdf")}
returns false.
Comments