Some examples of working with single dimension arrays:
// Declare array with values %%locations = array('Jacksonville, FL', 'Toronto, Canada', 'Orlando, FL', 'Chicago, IL'); // Declare new empty array %%copied = array(); foreach(%%locations as %%location) { // Add element to array %%copied[] = %%location; } |
And with a for loop (NOTE: You must use curly brackets when using a variable as the key).
for (%%i=0; %%i<%%count; %%i++) { %%output .= "<br>".%%locations{%%i}; }
And with a 2-dimension array (or hashtable):
// Declare array with values %%locations = array('Toronto' => 'Ontario', 'Jacksonville' => 'FL', 'Orlando' => 'FL', 'Chicago' => 'IL'); foreach (%%locations as %%key => %%value) { %%output .= "City: ".%%key." State/Province".%%value; } |
No comments:
Post a Comment