[WebDNA] WebDNA Associative Arrays?

This WebDNA talk-list message is from

2012


It keeps the original formatting.
numero = 108681
interpreted = N
texte = Hello! I was thinking a bit about arrays tonight (from the recent conversations). Currently, I think WebDNA arrays are a bit contrived, but maybe have potential if there was some useful functions to work with them. One of things WebDNA lacks (correct me if I am wrong) is the ability for associative arrays... which are arrays that have unique key's for their values... instead of indexed arrays, which are what webdna's arrays are:..1,2,3,4 etc.. Anyway, I've made a stab at associative arrays using WebDNA. It is a custom function called: foreach_2d. --- name: foreach_2d params: forarray: name of array (required) foraction: something for the function to do forkey: name of key (optional) forvalue: name of value (optional) Example call (watch for email line breaks): [foreach_2d forarray=a_assoc_array&forkey=key&forvalue=value&foraction=[url][a_action][/url]] Requirements: Only works with 2 dimensional arrays, with the second dimension being a static 2.. ie.: [arrayset name=somearray&dims=100,2] --- Anyway, food for thought perhaps... I should probably zip up the test file so that it travels without email line breaks... let me know if anyone needs that. Example template below (watch for email line breaks): (Drop this file into your WebDNA environment for testing) --------------- copy below ----------------------------------------  Array Stuff - EDC [!] Experiment by EDC into Associative arrays using WebDNA and then using those arrays in a foreach loop, inspired by PHP's foreach function. Like I said, just ideas for now. [/!] [!] ** grep is just to help with seeing the array ** [/!] [arrayset name=a_assoc_array&dim=3,2][grep search=[%0D%0A]&replace=] (1,1)=key1& (1,2)=value1& (2,1)=key2& (2,2)=value2& (3,1)=key3& (3,2)=value3 [/grep][/arrayset] [function name=foreach_2d] [if "[url][params_string][/url]" ^ "forvalue"] [then] [if "[url][params_string][/url]" ^ "forkey"] [then] [!] ** both key and value are supplied ** [/!] [loop start=1&end=[interpret][[forarray](DimSize_1)][/interpret]] [text][forkey]=[interpret][[forarray]([index],1)][/interpret][/text] [text][forvalue]=[interpret][[forarray]([index],2)][/interpret][/text] [return][interpret][unurl][foraction][/unurl][/interpret][/return] [/loop] [/then] [else] [!] ** just key is supplied ** [/!] [loop start=1&end=[interpret][[forarray](DimSize_1)][/interpret]] [text][forvalue]=[interpret][[forarray]([index],2)][/interpret][/text] [return][interpret][unurl][foraction][/unurl][/interpret][/return] [/loop] [/else] [/if] [/then] [else] [!] ** No key or value is supplied ** [/!] [loop start=1&end=[interpret][[forarray](DimSize_1)][/interpret]] [return][interpret][unurl][foraction][/unurl][/interpret][/return] [/loop] [/else] [/if] [/function]
[text]a_action=[url][raw] Not much use except repeating text
[/raw][/url][/text] No key or value name supplied:
[foreach_2d forarray=a_assoc_array&foraction=[url][a_action][/url]]
[text]a_action=[url][raw] [value]
[/raw][/url][/text] Just value supplied (example):
Options are:
[foreach_2d forarray=a_assoc_array&forvalue=value&foraction=[url][a_action][/url]]
[text]a_action=[url][raw] [key]=[value]
[/raw][/url][/text] Key and value supplied (example):
Contents of Array is:
[foreach_2d forarray=a_assoc_array&forkey=key&forvalue=value&foraction=[url][a_action][/url]] --------------- copy above ---------------------------------------- Cheers, Donovan -- Donovan Brooke Euca Design Center www.euca.us Associated Messages, from the most recent to the oldest:

    
  1. [WebDNA] WebDNA Associative Arrays? (Donovan Brooke 2012)
Hello! I was thinking a bit about arrays tonight (from the recent conversations). Currently, I think WebDNA arrays are a bit contrived, but maybe have potential if there was some useful functions to work with them. One of things WebDNA lacks (correct me if I am wrong) is the ability for associative arrays... which are arrays that have unique key's for their values... instead of indexed arrays, which are what webdna's arrays are:..1,2,3,4 etc.. Anyway, I've made a stab at associative arrays using WebDNA. It is a custom function called: foreach_2d. --- name: foreach_2d params: forarray: name of array (required) foraction: something for the function to do forkey: name of key (optional) forvalue: name of value (optional) Example call (watch for email line breaks): [foreach_2d forarray=a_assoc_array&forkey=key&forvalue=value&foraction=[url][a_action][/url]] Requirements: Only works with 2 dimensional arrays, with the second dimension being a static 2.. ie.: [arrayset name=somearray&dims=100,2] --- Anyway, food for thought perhaps... I should probably zip up the test file so that it travels without email line breaks... let me know if anyone needs that. Example template below (watch for email line breaks): (Drop this file into your WebDNA environment for testing) --------------- copy below ----------------------------------------  Array Stuff - EDC [!] Experiment by EDC into Associative arrays using WebDNA and then using those arrays in a foreach loop, inspired by PHP's foreach function. Like I said, just ideas for now. [/!] [!] ** grep is just to help with seeing the array ** [/!] [arrayset name=a_assoc_array&dim=3,2][grep search=[%0D%0A]&replace=] (1,1)=key1& (1,2)=value1& (2,1)=key2& (2,2)=value2& (3,1)=key3& (3,2)=value3 [/grep][/arrayset] [function name=foreach_2d] [if "[url][params_string][/url]" ^ "forvalue"] [then] [if "[url][params_string][/url]" ^ "forkey"] [then] [!] ** both key and value are supplied ** [/!] [loop start=1&end=[interpret][[forarray](DimSize_1)][/interpret]] [text][forkey]=[interpret][[forarray]([index],1)][/interpret][/text] [text][forvalue]=[interpret][[forarray]([index],2)][/interpret][/text] [return][interpret][unurl][foraction][/unurl][/interpret][/return] [/loop] [/then] [else] [!] ** just key is supplied ** [/!] [loop start=1&end=[interpret][[forarray](DimSize_1)][/interpret]] [text][forvalue]=[interpret][[forarray]([index],2)][/interpret][/text] [return][interpret][unurl][foraction][/unurl][/interpret][/return] [/loop] [/else] [/if] [/then] [else] [!] ** No key or value is supplied ** [/!] [loop start=1&end=[interpret][[forarray](DimSize_1)][/interpret]] [return][interpret][unurl][foraction][/unurl][/interpret][/return] [/loop] [/else] [/if] [/function]
[text]a_action=[url][raw] Not much use except repeating text
[/raw][/url][/text] No key or value name supplied:
[foreach_2d forarray=a_assoc_array&foraction=[url][a_action][/url]]
[text]a_action=[url][raw] [value]
[/raw][/url][/text] Just value supplied (example):
Options are:
[foreach_2d forarray=a_assoc_array&forvalue=value&foraction=[url][a_action][/url]]
[text]a_action=[url][raw] [key]=[value]
[/raw][/url][/text] Key and value supplied (example):
Contents of Array is:
[foreach_2d forarray=a_assoc_array&forkey=key&forvalue=value&foraction=[url][a_action][/url]] --------------- copy above ---------------------------------------- Cheers, Donovan -- Donovan Brooke Euca Design Center www.euca.us Donovan Brooke

DOWNLOAD WEBDNA NOW!

Top Articles:

Talk List

The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...

Related Readings:

Re:quit command on NT (1997) Limitations on fields? Server is crashing (1997) Large sites (2003) Limiting user access to .tmpl files (1997) 2nd WebCatalog2 Feature Request (1996) Checkboxes (1998) Extra carriage returns (1999) Database wiped clean (2005) Can GMT be called from the OS ? (2004) Include from DB (2002) HELP WITH DATES (1997) PROBLEMS WITH PROTECT TAG (2004) OT: Poll Please (2002) Possible Bug in 2.0b15.acgi (1997) Finding max value for a field (1997) suffix mapping, use of cache, etc. (1997) Comments in db? (1997) [protect admin] (1997) [WriteFile] problems (1997) Playin Tricks (2006)