Feb 14, 2008

cf arrays,structures and files by Raghuram Reddy.G

Posted by: raghuramCF blog

Coldfusion ( CF )  Arrays , cftags, functions 

             by Raghuram Reddy.G

Hi, I am very much happy to share the info. with you. 

 

As we know that an array is a tabular structure used to hold data.

In ColdFusion, arrays are used to temporarily store data.

Unlike the other programming languages the ColdFusion arrays index starts from 1.

It means the count and the index starts from the same point.

If the array has 10 elements,  the first value index is 1 and the last value index is 10.

so there is no confusion in ColdFusion arrays..... right !

 

Creating an Array in CF

 

The thing you need to create ColdFusion array is

syntax :             <cfset  myArray=ArrayNew(dim)> 

                     Here the dim is  of which dimension array you want to create.

                        The dimension may be 1,2,3.

If you want to create 1 dim. array , specify 1 in place of dim, same for 2 and 3.

( For more than 3 dim. arrays creation, cf uses different methods..we will discuss them later...)

Example:  

        <cfset  myArr=ArrayNew(1)>

          <cfset myArr[1]="Raghu">

          <cfset myArr[2]="Ram">

          <cfset myArr[3]="Reddy">

        <cfloop index="i" from="1" to="3">

 

           <cfoutput>#myArr[i]#</cfoutput>


        </cfloop>

 

 or you can replace the whole cfloop with cfdump . But it is useful only for debugging purpose.

Just cfdump will display all the values hold by array in a neatly and readable format.

                        <cfdump var="#myArr#"> 

and other way to insert the values into an array is as follows.but it will work if and only 

<cfset tmp = ArrayAppend(groceries,"Bread")>

 

 

 

 

Previously...

There are not enough entries to display at this time

Search

About The Author

Recent Comments