Arrays

From CEW

Jump to: navigation, search

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.

Supported by: Image:Railo-2.0.1.png


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.

Supported by: Image:Railo.png


ArrayFirst()

The equivalent to ListFirst(), returns the first element in an array.

Supported by: Image:Railo.png


ArrayIndexExists()

The equivalent to StructKeyExists(), returns true if the specified index exists.

Supported by: Image:Railo.png


ArrayLast()

The equivalent to ListLast(), returns the last element in an array.

Supported by: Image:Railo.png


ArrayMerge()

Returns an array with two arrays merged into one.

Supported by: Image:Railo.png


ArrayReverse()

Returns a new array with elements in reverse order.

Supported by: Image:Railo.png


ArraySlice()

Returns a slice of the original array, defined by offset and length.

Supported by: Image:Railo.png


ArrayToStruct()

Converts an array to a struct.

Supported by: Image:Railo.png


[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.

Supported by: Image:Railo.png Image:ColdFusion-8.png

[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} }

Supported by: Image:Railo.png Image:ColdFusion-8.0.1.png


[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'}

Supported by: Image:Railo.png

Personal tools