To create an EWD Session array within a back-end Caché script, the normal technique is to first create a local array and then merge it into the EWD Session Array:

   s myArr(1,"city")="London"
   s myArr(1,"country")="UK"
   s myArr(2,"city")="New York"
   s myArr(2,"country")="USA"
   d deleteFromSession^%zewdAPI("myArray",sessid)
   d mergeArrayToSession^%zewdAPI(.myArr,"myArray",sessid)

This would create an EWD Session array named myArray that would have the same physical structure as the temporary local array named myArr. Note the use of deleteFromSession to clear down any existing values within the Session Array and also notice the way myArr is called by reference, indicated by the period preceeding the array name.

To process or manipulate an EWD Session array within a back-end Caché script, you use the reverse process, merging the EWD Session array to a local array which can then be easily manipulated:

   k myArr
   d mergeArrayFromSession^%zewdAPI(.myArr,"myArray",sessid)
   s city1=myArr(1,"city")

When accessing EWD Session Arrays within EWD Pages, you'll normally used the ewd:forEach custom tag which allows you to iterate through a specified level within the Session Array and optionally retrieve associated data. For example:

   <h3>This example is iterating through a Session Array</h3>

   <ewd:forEach sessionName="myArray" index="$lineNo">
       Line No: <?= $lineNo ?>
     <ewd:forEach sessionName="myArray" param1="$lineNo" index="$id" return="$data">
         ID: <?= $id ?> ; value: <?= $data ?>

Note the use of the index attribute. This returns the next value of the current subscript. The outer ewd:forEach tag will iterate through the first subscript. The inner, nested ewd:forEach tag iterates through the second subscript, indicated by locking the first subscript to the value returned by the outer ewd:forEach tag: param1="$lineNo". By repeating this process using paramn you can iterate through any EWD Session Array of any depth.