Arrays
From CEW
Contents |
ArrayContains()
The equivalent to ListContains(), and returns the index of the array element which contains the specified string. ArrayContainsNoCase() is the case-insensitive version. Note: An array element must contain at least the string, but can be longer. See ArrayFind() if exact matches are required.
ArrayFind()
The equivalent to ListFind(), and returns the index of an array which matches exactly the specified string. Note: An array element must entirely match the string. See ArrayContains() if you need a less strict approach.
ArrayFirst()
The equivalent to ListFirst(), returns the first element in an array.
ArrayIndexExists()
The equivalent to StructKeyExists(), returns true if the specified index exists.
ArrayLast()
The equivalent to ListLast(), returns the last element in an array.
ArrayMerge()
Returns an array with two arrays merged into one.
ArrayReverse()
Returns a new array with elements in reverse order.
ArraySlice()
Returns a slice of the original array, defined by offset and length.
ArrayToStruct()
Converts an array to a struct.
[edit] Inline Array
Inline arrays allow you to create an array in a more convenient fashion.
Railo has supported the Array(1,2,3) notation from version 1.
Adobe added {1,2,3} notation to ColdFusion 8, with several restrictions.
[edit] Nested Inline Array
With Railo, Array() is a function and thus can be nested:
Array( Array(1,2,3) , Array(4,5,6) , Array(7,8,9) )
The CF8 notation did not initially support nesting. With CF8.0.1 it is now possible to nest inline arrays:
{ {1,2,3} , {4,5,6} , {7,8,9} }
[edit] Url Array conversion
Normally, passing multiple values with the same name in a query string will create a list.
For example, with index.cfm?car=ford&car=honda&car=skoda, you get car = 'ford,honda,skoda'
This causes problems if you have values with commas in them:
Using index.cfm?car=ford&car=honda,civic&car=honda,accord&car=skoda results in car = 'ford,honda,civic,honda,accord,skoda'
A solution to this is to use Array conversion, by suffixing the parameter name like so:
index.cfm?car[]=ford&car[]=honda,civic&car[]=honda,accord&car[]=skoda
This then produces an array:
car = {'ford','honda,civic','honda,accord','skoda'}




