Skip to content
This repository

Update cfml100mins.markdown #71

Merged
merged 1 commit into from over 2 years ago

2 participants

ntunney Mike Henke
ntunney

Expanded array creation to include arrayNew() for CF8- as well as multidimensional arrays.

Mike Henke
Owner

Thanks. Looks great!

Mike Henke mhenke merged commit c9f431d into from
Mike Henke mhenke closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 18, 2012
ntunney ntunney Update cfml100mins.markdown 6e91106
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 27 additions and 1 deletion. Show diff stats Hide diff stats

  1. +27 1 cfml100mins.markdown
28 cfml100mins.markdown
Source Rendered
@@ -788,7 +788,9 @@ There are some other ways to loop over queries, and one that comes in handy for
788 788
789 789 Often we need to organize a group and put them into a *collection*. There are two main types of collections: **arrays** and **structures**.
790 790
791   -An **array** is a number-indexed list. Picture a city block of houses. Together they form an array and their addresses are the **indices**. Each house on the block will have a unique address. Some addresses might be empty, but the addresses are all in a specific order. The **index** is the address of a specific element inside the array. In CFML the index always begins with "1". An array is defined in CFML as an opening ```[``` then zero or more elements, and a closing ```]```. Try out this code:
  791 +An **array** is a number-indexed list. Picture a city block of houses. Together they form an array and their addresses are the **indices**. Each house on the block will have a unique address. Some addresses might be empty, but the addresses are all in a specific order. The **index** is the address of a specific element inside the array. In CFML the index always begins with "1". Say that again, **ColdFusion uses 1 based arrays**. This is different than some other languages and is very important to note.
  792 +
  793 +An array can be created 2 ways in CFML. Starting with ColdFusion 9 we can use shorthand notation to create an array. We do this as an opening ```[``` then zero or more elements, and a closing ```]```. Try out this code:
792 794
793 795 #### Tag Syntax
794 796
@@ -812,6 +814,30 @@ writeDump(var = ArrayLen(favorite_colors));
812 814 </cfscript>
813 815 ```
814 816
  817 +Prior to ColdFusion 9 or if you need an array with multiple dimensions (think associative arrays and matrices) we can use the ```arrayNew()``` function. ```ArrayNew()``` takes a single argument which is the number of dimensions the array has. We can create up to three dimensional arrays in ColdFusion.
  818 +#### Tag Syntax
  819 +
  820 +```cfm
  821 +<cfset myArray = arrayNew(2) />
  822 +<cfset myArray[1][1] = 'Hammer' />
  823 +<cfset myArray[1][2] = 'Nail' />
  824 +<cfset myArray[2][1] = 'Screwdriver' />
  825 +<cfset myArray[1][2] = 'Screw' />
  826 +
  827 +```
  828 +
  829 +#### Script Syntax
  830 +
  831 +```cfm
  832 +<cfscript>
  833 + myArray = arrayNew(2);
  834 + myArray[1][1] = 'Hammer';
  835 + myArray[1][2] = 'Nail';
  836 + myArray[2][1] = 'Screwdriver';
  837 + myArray[1][2] = 'Screw';
  838 +</cfscript>
  839 +```
  840 +
815 841 Keep going with these, but try to understand what each instruction is doing before we explain them:
816 842
817 843 #### Tag Syntax

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.