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

Freeze (2003) WebCat b15 Mac plug-in (1997) NetSplat and WebCat2 (1997) [lookup] vs. [search] (1998) searching multiple databases (1997) WebCat2b14MacPlugIn - [include] doesn't hide the search string (1997) charging? (2001) Pithy questions on webcommerce & siteedit (1997) Requiring that certain fields be completed (1997) Monitoring Script (2008) View Source from cache (1997) [Sum] function? (1997) 2.0 Info (1997) Web Catalog 2 demo (1997) [WebDNA] writing pdfs on the fly (Avery labels #5160) (2010) SKU (1997) remotely add + sign (1997) webdelivery.html and webna (1997) Format all of a sudden doesn't work (1997) incrementing a counter remotely? (1999)