Get the array lenght in Coldfusion

When dealing with array, we cannot run away for looping. Because only with looping, you can cut short your hard coded script to read the value from array. And also you no need to worry about the dynamic of array.

Arraylen is the function that determines the number of elements in an array.

The syntax is ArrayLen(array)


<!— Assigning value into 3D array —>

<cfset ResultsArray[1][1][1] = ‘a’>
<cfset ResultsArray[1][1][2] = ‘b’>

<cfset ResultsArray[1][2][1] = ‘3’>
<cfset ResultsArray[1][2][2] = ‘4’>

<cfset ResultsArray[2][1][1] = ‘z’>
<cfset ResultsArray[2][1][2] = ‘x’>

<cfset ResultsArray[2][2][1] = ‘m’>
<cfset ResultsArray[2][2][2] = ‘p’>

<cfset ResultsArray[3][1][1] = ‘ww’>
<cfset ResultsArray[3][1][2] = ‘xx’>

<cfset ResultsArray[3][2][1] = ’22’>
<cfset ResultsArray[3][2][2] = ‘cc’>

<!— Read the array lenght for 1st D, 2nd D, and 3th D —>
#ArrayLen(ResultsArray)#<br> <!— Get the lehgth of 1st D —>
#ArrayLen(ResultsArray[1])#<br><!— Get the lehgth of 2nd D —>
#ArrayLen(ResultsArray[1][1])#<br><!— Get the lehgth of 3th D —>

Leave a Reply, pub-3772983857049267, DIRECT, f08c47fec0942fa0
%d bloggers like this: