[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 acustom function called: foreach_2d.---name: foreach_2dparams: 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 usingthose 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 BrookeEuca Design Centerwww.euca.us
Associated Messages, from the most recent to the oldest:
|
- [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 acustom function called: foreach_2d.---name: foreach_2dparams: 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 usingthose 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 BrookeEuca Design Centerwww.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:
Nested vs conditional (1997)
Slightly OT: [sendmail] help (2003)
New WebCatalog site! (1997)
[WebDNA] DNA suffix (2008)
xml - amazon bug and sed q: (2004)
WCS Newbie question (1997)
ListVariables Problem (2003)
More on screen refresh causing duplicate order entries (1998)
[WebDNA] Date error (2017)
[WebDNA] Amazon EC2 (2009)
Help name our technology! (1997)
WebCat2b13MacPlugIn - [showif][search][/showif] (1997)
Superfilous Characters (1998)
Re:quit command on NT (1997)
What if SSL server down? MAC (1997)
lookup (1998)
Talk List Suggestions (1997)
Disappearing records (2002)
Error Lob.db records error message not name (1997)
OK, here's a new one (2002)