Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
natebaca #1
creating a multidimensional array
How can I combine two arrays in cfscript to form one multidimensional array?
For example, I have two arrays:
firstarray[1]=fred;
firstarray[2]=jim;
secondarray[1]=joe;
secondarray[2]=sam;
and would like to turn them into one array:
combinedarray[1][1]=fred;
combinedarray[1][2]=jim;
combinedarray[2][1]=joe;
combinedarray[2][2]=sam;
Any help would be greatly appreciated.
natebaca Guest
-
Problem with multidimensional array
Hi! I'm new on this forum, and in the Macromedia Flash development. I've read some books, like the Flash MX 2004 game development (C. S. Murray,... -
Multidimensional array: see if 1st key is available
Hi, I've got an multidimensional array $ret = $country_code; Now I want to see if $countryCode is even in that array, because if it's not, it... -
copying a multidimensional array
Hi: whatz the best way to copy an multidimensional array onto another. I have never used something like clone, just want to know whatz the easiest... -
Split multidimensional array into 4 multidimensional arrays
Hello everyone, I have a multidimensional array that I need to split into 4 multidimensional arrays. I've tried the examples from the... -
Sorting a Multidimensional Array
I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02', -
Vamsee Krishna #2
Re: creating a multidimensional array
Hi,
Try using the ArrayAppend function.
<cfscript>
Firstarray = ArrayNew(1);
Secondarray = ArrayNew(1);
Combinedarray = ArrayNew(2); // even ArrayNew(1) will work
arrayset(Firstarray ,1,2,"jim");
arrayset(Secondarray ,1,2,"fred");
ArrayAppend(Combinedarray ,Firstarray);
ArrayAppend(Combinedarray ,Secondarray);
</cfscript>
<cfdump var="#Combinedarray#">
Thanks,
Vamsee
"natebaca" <webforumsuser@macromedia.com> wrote in message
news:cvs2pk$kob$1@forums.macromedia.com...> How can I combine two arrays in cfscript to form one multidimensional
> array?
>
> For example, I have two arrays:
>
> firstarray[1]=fred;
> firstarray[2]=jim;
>
> secondarray[1]=joe;
> secondarray[2]=sam;
>
> and would like to turn them into one array:
> combinedarray[1][1]=fred;
> combinedarray[1][2]=jim;
> combinedarray[2][1]=joe;
> combinedarray[2][2]=sam;
>
> Any help would be greatly appreciated.
>
Vamsee Krishna Guest
-
Rob #3
RE: creating a multidimensional array
There are two examples listed below.
Here is an example that loops through the arrays as it builds the new one:
<CFSCRIPT>
arr1 = ARRAYNEW(1);
arr1[1] = "fred";
arr1[2] = "jim";
arr2 = ARRAYNEW(1);
arr2[1] = "joe";
arr2[2] = "sam";
array_name_list = "arr1,arr2";
arr3 = ARRAYNEW(2);
FOR(list_idx = 1; list_idx LTE LISTLEN(array_name_list); list_idx = list_idx + 1){
array_name = LISTGETAT(array_name_list,list_idx);
FOR(arr_idx = 1; arr_idx LTE ARRAYLEN(EVALUATE(array_name)); arr_idx = arr_idx + 1){
arr3[list_idx][arr_idx] = EVALUATE(array_name&"["&arr_idx&"]");
}
}
</CFSCRIPT>
<CFDUMP VAR="#arr3#">
Here is a simpler example that appends the arrays to the new array:
<CFSCRIPT>
arr1 = ARRAYNEW(1);
arr1[1] = "fred";
arr1[2] = "jim";
arr2 = ARRAYNEW(1);
arr2[1] = "joe";
arr2[2] = "sam";
arr3 = ARRAYNEW(2);
tmp = ARRAYAPPEND(arr3,arr1);
tmp = ARRAYAPPEND(arr3,arr2);
</CFSCRIPT>
<CFDUMP VAR="#arr3#">
Reference:
How can I combine two arrays in cfscript to form one multidimensional array?
For example, I have two arrays:
firstarray[1]=fred;
firstarray[2]=jim;
secondarray[1]=joe;
secondarray[2]=sam;
and would like to turn them into one array:
combinedarray[1][1]=fred;
combinedarray[1][2]=jim;
combinedarray[2][1]=joe;
combinedarray[2][2]=sam;
Any help would be greatly appreciated.
Rob Guest



Reply With Quote

