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

consolidating orders (2000) WebCatalog2 for NT Beta Request (1997) [removelineitem] not quite working inside [formvariables] loop (2001) Help! WebCat2 bug (1997) [WebDNA] ImageMagick function library updated (2009) Adding multiple items to Cart (1999) HTML Editors (1997) TeaRoom Order fields email account remain empty even though thewy are filled. (1997) Snake Bites (1997) Orderfile Question (2003) Problem (1997) missing records (1998) [WebDNA] WebDNA.us site speed (2011) no global [username] or [password] displayed ... (1997) Sorting nested search (2003) Slightly [OT] Trying to get clients SQL system going (2005) Securing/hiding database file (2000) WebCatalog 4.0 has been released! (2000) lookup command (1999) Date search - yes or no (1997)