ArrayClear ColdFusion Help

The ArrayCl ear function deletes all elements in an array. That is, it actually removes all elements from the array (as opposed to assigning some default value such as the empty string or zero). The result is a string oflength zero in all dimensions. The function takes a single argument: ArrayCl ear(Array).

A Boolean value of True is returned upon successful completion of the deletions.

ArrayResiz

ArrayResi ze resizes an array to a specified minimum number of elements. The key word here is minimum. For instance to resize an existing array with four elements to ‘three elements has no effect because you are resizing to a minimum of three elements and the existing four elements already exceed three elements. However resizing the same array to seven elements results in a seven-element array

This resizing process leaves new elements in an unusable empty state and the elements still need values assigned to them to be used. Allaire recommends using ArrayResize to “create the elements of a large array-before assigning values to the elements. This process is supposed to provide performance gains on arrays of more than 500 elements as compared to enabling Cold Fusion to create each element with each CFSETstatement that assigns an initial value to an element.

To use ArrayResize simply provide the name of the array and the minimum number of elements as arguments: ArrayResize(Array, Si ze).

This function returns the Boolean value of True upon successful completion of the resizing.

ArraylsEmpty

ArrayIs Empty is a simple function: it tests whether an array is completely empty and returns True if it is and False if it is not. The function is used as follows: ArrayIsEmpty(Array) .

Consider the following example: Imagine you have-a three-element array called Test-Array with values assigned to each element in the array. The following code assigns the value False to Before and the value True to After:

<CFSET Before – ArrayIsEmpty(TestArray>
<CFSET Result – ArrayClear(TestArray>
<CFSET After – ArrayIsEmpty(TestArray>

IsArray

As the name suggests the Is Array function tests whether a given data structure is an array. The data structure to test is passed as an argument to the function and the function returns the Boo1eCIIIvalue True if the data structure is an array and False if it isn’t.

Optionally the function can also test whether a data structure is an array of a specified dimension. The syntax of the function is IsArray(Array Omens; on) where the dimension argument is optional

ListToArray and Array ToList

The final functions you will look at are L; stToArray and ArrayToL; st, which are used to convert data structures befween lists and arrays.

ListToArray takes a list and an optional delimiter specification as arguments and returns a single-dimensional array with each array element containing a single list element from the original list: L; stToArray(List Delimiter). The resulting array is returned by the function.

ArrayToL i st works in reverse. Given a one-dimensional array and an optional delimiter the elements in the array are copied into a list delimited by the specified delimiter character (the default delimiter is, of course, a comma): ArrayToL i st(Array ,Oelimite r). The resulting list is returned by the function.

Posted on November 16, 2015 in Working with cold Fusion Data Structure

Share the Story

Back to Top
Share This