Difference between revisions of "FOREACH"
From Recital Documentation Wiki
Yvonnemilne (Talk | contribs) |
Yvonnemilne (Talk | contribs) |
||
Line 4: | Line 4: | ||
==Purpose== | ==Purpose== | ||
− | + | Iterate over each element of an array or member of an object | |
==Syntax== | ==Syntax== | ||
+ | FOREACH <array> AS <value> | FOREACH <array> AS <key> => <value> | ||
+ | ENDFOR | ||
==See Also== | ==See Also== | ||
− | + | [[AADD()]], [[AAVERAGE()]], [[ABROWSE()]], [[ACHOICE()]], [[ACOL()]], [[ACOPY()]], [[ADEL()]], [[ADESC()]], [[ADIR()]], [[AELEMENT()]], [[AFIELDS()]], [[AFILL()]], [[AINS()]], [[ALEN()]], [[AMAX()]], [[AMIN()]], [[APPEND FROM ARRAY]], [[AROW()]], [[ARRAY()]], [[ASIZE()]], [[ASORT()]], [[ASTORE()]], [[ASTRING()]], [[ASUBSCRIPT()]], [[ASUM()]], [[COPY TO ARRAY]], [[DECLARE]], [[DIMENSION]], [[DO WHILE]], [[FOR]], [[GATHER]], [[IN_ARRAY()]], [[LOCAL]], [[PRIVATE]], [[PUBLIC]], [[RELEASE]], [[RESTORE]], [[SAVE]], [[SCATTER]] | |
Line 24: | Line 26: | ||
foreach numbers as elem | foreach numbers as elem | ||
? elem * elem | ? elem * elem | ||
+ | endfor | ||
+ | |||
+ | // associative array | ||
+ | private myarray = array("Name" => "Recital", "Description" => "database") | ||
+ | foreach myarray as key => value | ||
+ | echo "key=" + key + " value=" + value | ||
endfor | endfor | ||
</code> | </code> |
Revision as of 15:00, 17 November 2009
Purpose
Iterate over each element of an array or member of an object
Syntax
FOREACH <array> AS <value> | FOREACH <array> AS <key> => <value>
ENDFOR
See Also
AADD(), AAVERAGE(), ABROWSE(), ACHOICE(), ACOL(), ACOPY(), ADEL(), ADESC(), ADIR(), AELEMENT(), AFIELDS(), AFILL(), AINS(), ALEN(), AMAX(), AMIN(), APPEND FROM ARRAY, AROW(), ARRAY(), ASIZE(), ASORT(), ASTORE(), ASTRING(), ASUBSCRIPT(), ASUM(), COPY TO ARRAY, DECLARE, DIMENSION, DO WHILE, FOR, GATHER, IN_ARRAY(), LOCAL, PRIVATE, PUBLIC, RELEASE, RESTORE, SAVE, SCATTER
Description
Example
numbers = array(1,2,3,4,5,6,7,8,9,10) foreach numbers as elem ? elem * elem endfor // associative array private myarray = array("Name" => "Recital", "Description" => "database") foreach myarray as key => value echo "key=" + key + " value=" + value endfor