Array Operation
numero = 84You can't code PHP without knowing about array's because array's are just about the basis of PHP. WebDNA does not need active use of array's like other languages because of its flat-file database system: with WebDNA, array's can easily and advantageously be replaced by databases to serve as virtual unlimited permanent array's.
So far you have been using variables quite a lot. You have put numbers into [math ] variables, and you have put text into [text] variables. But you have only done this one at a time: you've put one number into a variable, or one string of text. So one variable was holding one piece of information. An array is a variable that can hold more than one piece of information at a time.An array allows the programmer to store more than one value in a variable, whilst retaining a single reference. If we think of a variable as a single slot in memory (or a box) that can contain data of a certain type - number, character, etc. - then an array is the equivalent of a box divided into partitions, each containing a piece of data. The array context will allow the WebDNA programmer to create an array data object with up to five dimensions.A multi-dimensional array is an array of arrays. If we think of a one-dimensional array as a row of slots in a box, then a two dimensional array is a grid of slots, and a three dimensional array is a cube of slots. Beyond three dimensions it becomes difficult to conceptualize, but theoretically at least, arrays can have any dimension. WebDNA allows up to 5 dimensions
Parameters-Name - The variable name you specify to represent the array object.-Dim - Comma delimited series of numbers representing the array dimension sizes, i.e. '3,4,5', which would represent a 3x4x5 dimensioned array:[arrayset name=DOW&dim=7](1)=Sun&(2)=Mon&(3)=Tue&(4)=Wed&(5)=Thu&(6)=Fri&(7)=Sat[/arrayset]...the tag '[DOW(7)]' would resolve to 'Sat'You can replace array values with new ones:
[arrayset name=DOW](7)=joker[/arrayset]...the tag '[DOW(7)]' would resolve to 'joker'and add new ones, only if the original arrayset context specifies a size allowing to add new values:
[arrayset name=DOW&dim=8](1)=Sun&(2)=Mon&(3)=Tue&(4)=Wed&(5)=Thu&(6)=Fri&(7)=Sat[/arrayset][arrayset name=DOW](8)=Next week[/arrayset]...the tag '[DOW(8)]' would resolve to 'Next week'Here an example of a three-dimensional array:
[arrayset name=myarray&dim=2,2,2](1,1,1)=value1&(1,1,2)=value2&(1,2,1)=value3&(1,2,2)=value4[/arrayset]This creates an array, called 'myarray', that will persist for the duration of the template. Note that the 'index=value' pairs within the [arrayset] tags are optional when creating a new array. Array indices can be assigned at any time. When the 'dim' parameter is supplied with the arrayset context, it implies that this will be a new array object. Subsequent calls to arrayset, using the same variable name (and without using the ‘dim’ parameter), imply new index assignments to an existing array object. So after we have created the 'myarray' object using the line shown above, we can assign index value at a later time using:
[arrayset name=myarray](2,1,2)=value6&(2,2,2)=value7[/arrayset]Once you have created an array, you can access the 'elements' of the array using the following methods:You can use a 'global tag' reference to retrieve a single array element. Here is the syntax for the global method:
[<arrayname>(<index>)]
[myarray(1,1,1)][myarray(1,1,2)][myarray(1,2,2)][myarray(1,2,1)][myarray(2,1,1)][myarray(2,1,2)][myarray(2,2,2)][myarray(2,2,1)]would showvalue1value2value4 value3value6value7Another way would be to use the [arrayget] context to retrieve several index values. Here we will discuss using the [arrayget] contex
[arrayget name=myarray][loop start=1&end=2][loop start=1&end=2][loop start=1&end=2]Index [::::index],[::index],[index] = ([::::index],[::index],[index])<br>[/loop][/loop][/loop][/arrayget][arrayget] takes just one parameter; 'name', in which you place an existing array variable name. The (a,b,c,d,e) patterns evaluate to the corresponding index values. These patterns can be intermingled with other text, as shown.Index 1,1,1 = value1Index 1,1,2 = value2Index 1,2,1 = value3Index 1,2,2 = value4 Index 2,1,1 = Index 2,1,2 = value6Index 2,2,1 = Index 2,2,2 = value7[numdims] TagYou can use the [numdims] tag to retrieve the number of dimensions for an array. For example:
[arrayset name=array_1&dim=3,3,10][/arrayset]array_1 contains [arrayget name=array_1][numdims][/arrayget] dimensions.Results: array_1 contains 3 dimensions.You can also use the 'array name' global tag to retrieve the number of dimension in a named array object. Here is the code:
[arrayset name=array_1&dim=3,3,10][/arrayset]array_1 contains [array_1(numdims)] dimensions.Results: array_1 contains 3 dimensions.[dimsize_] TagThe [dimsize_] tag is used to retrive the size of a given array dimension. Example:
[arrayset name=array_1&dim=3,4,5][/arrayset][arrayget name=array_1]array_1 has [numdims] dimensions:[loop start=1&end=[numdims]]Dimension [index] has [interpret][dimsize_[index]][/interpret] indexes.[/loop][/arrayget]Results: array_1 has 3 dimensions:Dimension 1 has 3 indexes.Dimension 2 has 4 indexes.Dimension 3 has 5 indexes.You can also access the dimension sizes using the global 'array name' tag, as follows:
[arrayset name=array_1&dim=3,4,5][/arrayset]array_1 has [array_1(NumDims)] dimensions:[loop start=1&end=[array_1(NumDims)]]Dimension [index] has [interpret][array_1(DimSize_[index])][/interpret] indexes.[/loop]Results: array_1 has 3 dimensions:Dimension 1 has 3 indexes.Dimension 2 has 4 indexes.Dimension 3 has 5 indexes. [arrayset name=...&dim=....]
You can't code PHP without knowing about array's because array's are just about the basis of PHP. WebDNA does not need active use of array's like other languages because of its flat-file database system: with WebDNA, array's can easily and advantageously be replaced by databases to serve as virtual unlimited permanent array's.
A multi-dimensional array is an array of arrays. If we think of a one-dimensional array as a row of slots in a box, then a two dimensional array is a grid of slots, and a three dimensional array is a cube of slots. Beyond three dimensions it becomes difficult to conceptualize, but theoretically at least, arrays can have any dimension. WebDNA allows up to 5 dimensions
[arrayset name=DOW&dim=7](1)=Sun&(2)=Mon&(3)=Tue&(4)=Wed&(5)=Thu&(6)=Fri&(7)=Sat[/arrayset]
[arrayset name=DOW](7)=joker[/arrayset]
[arrayset name=DOW&dim=8](1)=Sun&(2)=Mon&(3)=Tue&(4)=Wed&(5)=Thu&(6)=Fri&(7)=Sat[/arrayset]
[arrayset name=DOW](8)=Next week[/arrayset]
[arrayset name=myarray&dim=2,2,2]
(1,1,1)=value1&(1,1,2)=value2&(1,2,1)=value3&(1,2,2)=value4
[/arrayset]
[arrayset name=myarray](2,1,2)=value6&(2,2,2)=value7[/arrayset]
[<arrayname>(<index>)]
[myarray(1,1,1)]
[myarray(1,1,2)]
[myarray(1,2,2)]
[myarray(1,2,1)]
[myarray(2,1,1)]
[myarray(2,1,2)]
[myarray(2,2,2)]
[myarray(2,2,1)]
[arrayget name=myarray]
[loop start=1&end=2]
[loop start=1&end=2]
[loop start=1&end=2]
Index [::::index],[::index],[index] = ([::::index],[::index],[index])<br>
[/loop]
[/loop]
[/loop]
[/arrayget]
[arrayset name=array_1&dim=3,3,10][/arrayset]
array_1 contains [arrayget name=array_1][numdims][/arrayget] dimensions.
[arrayset name=array_1&dim=3,3,10][/arrayset]
array_1 contains [array_1(numdims)] dimensions.
[arrayset name=array_1&dim=3,4,5][/arrayset]
[arrayget name=array_1]
array_1 has [numdims] dimensions:
[loop start=1&end=[numdims]]
Dimension [index] has [interpret][dimsize_[index]][/interpret] indexes.
[/loop]
[/arrayget]
[arrayset name=array_1&dim=3,4,5][/arrayset]
array_1 has [array_1(NumDims)] dimensions:
[loop start=1&end=[array_1(NumDims)]]
Dimension [index] has [interpret][array_1(DimSize_[index])][/interpret] indexes.
[/loop]
DOWNLOAD WEBDNA NOW!
Amazon Web Services (AWS) README for Machine Image ID...
Tips and TricksA list of user-submitted tips ...
Technical Change HistoryThis Technical Change History provides a reverse chronological list of WebDNA changes...
WebDNA ModulesA list of the currently available modules...
WebDNA LibrariesA list of available libraries for WebDNA...
Download WebDNA ApplicationsWebDNA applications...
Deletes a folder from your website...
[JSONstore][JSONstore] stores a multidimentional JSON object into a WebDNA database...
[if]This context displays HTML or executes WebDNA conditionally only if the expression is true...
[findstring][FindString Source=...
[shell][shell] is a way to use the command line with your webserver...
[exclusivelock]Prevents other threads from simultaneously accessing a group of databases...