• My Pages
  • Comments
  • Add Link
  • Subscribe
  • Subscribe User
  • Edit (GUI)
  • Edit (Text)
  • Rename Page
  • Copy Page
  • Load Page
  • Save Page
  • Delete Page
  • Attachments
  • Check Spelling
  • Diffs
  • Info
  • Revert to this revision
  • XML
  • Render as Docbook
  • Print View
  • Raw Text
  • Delete Cache
  • Like Pages
  • Local Site Map
  • Remove Spam
  • Package Pages
  • Sync Pages

    Revision 3 as of 2014-01-27 11:41:28

    Clear message

    The following functions can be used to manipulate an array.

    Click each function name in the table below for more details of it, with examples.

    Functions

    Function

    Type

    Description

    push

    array

    Adds one or more elements to the end of an array and returns the new length of the array.

    pop

    array

    Removes the last element from an array and returns the value of that element.

    unshift

    array

    Adds one or more elements to the beginning of an array and returns the new length of the array. The other elements in the array are moved from their original position, i, to i+1.

    shift

    array

    Removes the first element from an array and returns that element. The remaining array elements are moved from their original position, i, to i-1.

    push

    Usage: array.push("x")

    Adds one or more elements to the end of an array and returns the new length of the array.

    Example:

    • myArray = ["a","b","c","d"]
    • echo "myArray = "+myArray
    • returnVal = myArray.push("e")
    • echo "myArray = "+myArray
    • echo "returnVal = "+returnVal

    Result:

    • a,b,c,d
    • a,b,c,d,e
    • 5

    pop

    Usage: array.pop()

    Removes the last element from an array and returns the value of that element.

    Example:

    • myArray = ["a","b","c","d"]
    • echo "myArray = "+myArray
    • returnVal = myArray.pop()
    • echo "myArray = "+myArray
    • echo "returnVal = "+returnVal

    Result:

    • a,b,c,d
    • a,b,c
    • d

    unshift

    Usage: array.unshift("x")

    Adds one or more elements to the beginning of an array and returns the new length of the array. The other elements in the array are moved from their original position, i, to i+1.

    Example:

    • myArray = ["a","b","c","d"]
    • echo "myArray = "+myArray
    • returnVal = myArray.unshift("_")
    • echo "myArray = "+myArray
    • echo "returnVal = "+returnVal

    Result:

    • a,b,c,d
    • _,a,b,c,d
    • 5

    shift

    Usage: array.shift()

    Removes the first element from an array and returns that element. The remaining array elements are moved from their original position, i, to i-1.

    Example:

    • myArray = ["a","b","c","d"]
    • echo "myArray = "+myArray
    • returnVal = myArray.shift()
    • echo "myArray = "+myArray
    • echo "returnVal = "+returnVal

    Result:

    • a,b,c,d
    • b,c,d
    • a


    CategoryFunctions