[FX.php List] A nagging question: Foreach

Jonathan Schwartz jschwartz at exit445.com
Mon Sep 22 16:48:27 MDT 2008


Hi Folks,

A long term nagging question:

Foreach syntax after an Instance
After an instance of FMPFind, FMNew, FMEdit, etc, we all use the 
standard foreach statement to retrieve values from a single record 
that was just created, edited, etc.  Sometime, I leave the foreach 
statement in the same place and retrieve the values later in the 
script.  When using the foreach statement in this second case, I find 
that I have to leave an empty line after the foreach.  Otherwise, 
things go wrong.


THIS IS FINE:
$findResult = $query->FMFind();
foreach($findResult['data'] as $key => $value)
$retrievedvalue = $value['retrievedvalue'][0];

THIS ISN'T:
$findResult = $query->FMFind();
foreach($findResult['data'] as $key => $value)
(SOME OTHER STATEMENTS); <---this goes wrong.
$retrievedvalue = $value['retrievedvalue'][0];

Is it implied that the line directly following a foreach statement 
acts on the line following it?

Is the proper syntax to either leave an empty line, of perhaps empty 
brackets after the foreach?:

IS THIS BETTER?:
$findResult = $query->FMFind();
foreach($findResult['data'] as $key => $value)
{}
(SOME OTHER STATEMENTS);
$retrievedvalue = $value['retrievedvalue'][0];


Jonathan

-- 
Jonathan Schwartz
Exit 445 Group
jonathan at exit445.com
http://www.exit445.com
415-370-5011


More information about the FX.php_List mailing list