Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
travelinrob #1
Looped Array Element Deletion
I want to loop through a structure of arrays using CFScript to delete an
element in the same position of each array.
Here is a snipet of code I use to set up the arrays:
<CFSCRIPT>
field_list =
"campaign,header_row,search,delivery_type,mail_typ e,ftp_server,ftp_user,ftp_pass
,mailto,mail_subject,ftp_location";
deliveryStr = STRUCTNEW();
FOR(idx = 1; idx LTE LISTLEN(field_list); idx = idx + 1)
{
field = LISTGETAT(fieldlist,idx);
"deliveryStr.#field#" = ARRAYNEW(1);
}
</CFSCRIPT>
This code works appropriately.
Now, say these arrays have 10 elements each and I want to delete the 5th
element of each because they are a collective set.
This is what I tried:
<CFSCRIPT>
FOR(idx = 1; idx LTE LISTLEN(field_list); idx = idx + 1)
{
field = LISTGETAT(fieldlist,idx);
tmp = ARRAYDELETEAT(EVALUATE("deliveryStr."&field),5);
}
</CFSCRIPT>
It does not error and if I output tmp it equates to 'YES'. But, if I CFDump
the structure, it has the same number of elements in the arrays as before the
attempt.
Any ideas?
I know I can list each field separately and it will work. I would rather loop
and save space.
Thanks.
Rob
travelinrob Guest
-
Array element doesn't keep struct value?
I'd like each of the following array elements to hold its own structure. <cfset TeamMemberDisplay = arraynew(1)> <cfset querystuct = structnew()>... -
Is there a function to see if something is an element of an array?
------------------------------------------------ On Tue, 30 Sep 2003 12:58:21 -0400, Dan Anderson <dan@mathjunkies.com> wrote: In general this... -
Is there a function to see if something is an element of an array?
I have a long list of IP addresses I am going to be reading in (using regexps) and then seperating out into a list of IP addresses. I don't want... -
Extract Array Element
HI! I have an array of 15 elements, however I dont want the fifth element. So, how can I extract it from the array so I would have 14 elements? ... -
Removing array element by key
How do i remove an element of an array by its key? I've tried array_s(p)lice to no avail. Either it chops too much or too little with seemingly... -
parvee #2
Re: Looped Array Element Deletion
Hi,
Try looping around structure and then try to delete from the each array.
Hope this helps,
Parvee:light;
parvee Guest
-
travelinrob #3
Re: Looped Array Element Deletion
Thank you, that does help. Not the looping through the structure, but looking
at the structure of arrays as an array of arrays. IE.- referencing the arrays
as structure[array] instead of structure.array. I might be able to get away
with looping through the structure, but, I cannot be sure that other arrays or
structures might be added to this structure that will not be of the same length
or have the same function as these main parts.
Solution:
FOR(idx = 1; idx LTE LISTLEN(field_list); idx = idx + 1)
{
field = LISTGETAT(field_list,idx);
tmp = ARRAYDELETEAT(deliveryStr[field],id);
}
Thanks again,
Rob
travelinrob Guest



Reply With Quote

