Array elements can store any values, including queries, structures, and other arrays. You can use assignment statements to populate an array. You can also use several of functions to populate an array with data, including ArraySet, ArrayAppend, ArrayInsertAt, and ArrayPrepend. These functions are useful for adding data to an existing array.
In particular, consider using the following techniques:
- Populating an array with the ArraySet function
- Populating an array with the cfloop tag
- Populating an array from a query
Populating an array with the ArraySet function
You can use the ArraySet function to populate a 1D array, or one dimension of a multidimensional array, with some initial value, such as an empty string or zero. This can be useful to create an array of a certain size, without adding data to it right away. One reason to do this is so that you can reference all the array indexes. If you reference an array index that does not contain some value, such as an empty string, you get an error.
The ArraySet function has the following form: