• News
  • Developer information
  • Projects & contributions
  • Forum
  • Issue tracker
  • Open Funding
  • Security
  • User groups
  • Support
  • Store
  • Company

  • Path

    ez.no / exponential / documentation / development / libraries / ez template / operators / array handling


    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.

    Operator

    Short description

    A

    S

    array

    Builds an array using specified elements.

    X

     

    merge

    Merges input array and all arrays passed as parameter into one array.

    X

     

    hash

    Builds an associative array.

    X

     

    unique

    Removes duplicate values from an array.

    X

     

    sum

    Calculates the sum of values in an array.

    X

     

    implode

    Joins array elements with a string.

    X

     

    explode

    Splits a string into an array of substrings, or splits an array into an array of two subarrays.

    X

    X

    extract

    Extracts a portion from an array or a string.

    X

    X

    extract_left

    Extracts a portion from the start of an array or a string.

    X

    X

    extract_right

    Extracts a portion from the end of an array or a string.

    X

    X

    begins_with

    Checks if array/string begins with a specific element/sequence.

    X

    X

    ends_with

    Checks if array/string ends with a specific element/sequence.

    X

    X

    repeat

    Repeats the contents of an array or a string.

    X

    X

    reverse

    Reverses the contents of an array or a string.

    X

    X

    insert

    Inserts an element/sequence at specified position in array/string.

    X

    X

    remove

    Removes element(s) from array or string.

    X

    X

    replace

    NOT IMPLEMENTED (yet)

    X

    X

    append

    Appends element(s) to arrays and strings.

    X

    X

    prepend

    Adds element(s) to start of an array or a string.

    X

    X

    compare

    Compares the contents of two arrays or strings.

    X

    X

    contains

    Checks if an array/string contains a specific element/sequence.

    X

    X

    array

    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).

    merge

    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).

    hash

    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').

    unique

    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).

    sum

    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.

    implode

    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".

    explode

    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') ).

    extract

    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".

    extract_left

    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".

    extract_right

    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!".

    begins_with

    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.

    ends_with

    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.

    repeat

    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* ".

    reverse

    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".

    insert

    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".

    remove

    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".

    replace

    Short summary:
    Not implemented, yet.

    Usage:
    Not implemented, yet.

    Full description:
    Not implemented, yet.

    Example(s):

    {Not implemented, yet.}

    returns: Not implemented, yet.

    append

    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".

    prepend

    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".

    compare

    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.

    contains

    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

    Contents

    Development

    Extensions
    Exponential datamodel
    Exponential tuning and stability
    Importing attribute data
    Kernel
    Libraries
        eZ xml
        eZ db
        eZ i18n
        eZ soap
        eZ template
           Basics
           Functions
           Operators
              Data fetch
              String handling
              Type handling
              Logical handling
              Arithmetics
              Control structure handling
              Array handling
              Image handling
              Miscellaneous
        eZ webdav
    Scripting
    Standards
    System overview
    Test Suite
    Using Doxygen to create API documenta...


    Created

    10/07/2003
    12:52:45 pm
    by Balazs Halasy

    Last updated

    10/02/2004
    11:10:07 am
    by Gunnstein Lye

    Authors

    Balazs Halasy
    Gunnstein Lye
    Bruce Morrison



    This page is part of the Exponential documentation. The documentation is available under the GNU Free Documentation License. All contributions will be released under the terms of this license.