CFLib.org – Common Function Library Project

ArrayReverse(InArray)

Last updated October 9, 2001

Version: 1 | Requires: ColdFusion 5 | Library: DataManipulationLib

 
Rated 0 time(s). Average Rating: 0

Description:
Reverses the order of elements in a one-dimensional array. This function takes a one-dimensional array and returns a new one with the values from the first in reverse order.

Return Values:
Returna a new one dimensional array.

Example:

view plain print about
<CFSET Numbers = "1,2,3,4,5">
<CFSET NumbersArray = ListToArray(Numbers)>
<CFSET NumbersArray = ArrayReverse(NumbersArray)>

<CFLOOP INDEX="I" FROM="1" TO="#ArrayLen(NumbersArray)#">
<CFOUTPUT>
#NumbersArray[I]#<BR>
</CFOUTPUT>
</CFLOOP>

Parameters:

Name Description Required
InArray One-dimensional array to be reversed. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Reverses the order of elements in a one-dimensional array.
 * 
 * @param InArray      One-dimensional array to be reversed. 
 * @return Returna a new one dimensional array. 
 * @author Raymond Simmons (raymond@terraincognita.com) 
 * @version 1.0, October 9, 2001 
 */

function ArrayReverse(inArray){
    var outArray = ArrayNew(1);
    var i=0;
        var j = 1;
    for (i=ArrayLen(inArray);i GT 0;i=i-1){
        outArray[j] = inArray[i];
        j = j + 1;
    }
    return outArray;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
29 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson