[FX.php List] foreach vs. first item in array

Charles Ross chivalry at mac.com
Tue Dec 13 15:36:44 MST 2005


Both in the FX.php in 8 Hours book and here on this mailing list,  
I've seen this line of code to extract a single item from the object  
returned with an FMFind():

foreach($returnedResult['data'] as $key => $value);

 From what I understand, this is useful when there should be a single  
record returned in $returnedResult. If that's the case, why not use:

$value = $returnedResult['data'][0];

Is there an advantage to using the foreach rather than the array  
index version? I did some testing, and it seemed to work the same,  
and the latter one seems easier to read and more straightforward, so  
I'm wondering if I'm missing something.

Thanks,
Chuck Ross


More information about the FX.php_List mailing list