[FX.php List] A nagging question: Foreach

Leo R. Lundgren leo at finalresort.org
Mon Sep 22 17:25:05 MDT 2008


Hmm, okey :) I'm not really sure about how FX works, but I guess  
there is some use for it then :-)

It would probably be possible to do this as well:

	$value = $findResult[count($findResult) - 1)];

It assigns $value once instead of $key and $value once for each found  
record even though you just want the last one. Well, if the FX array  
is a normal one, that is :)


23 sep 2008 kl. 01.15 skrev Bob Patin:

> Leo,
>
> I use it when I'm pulling data from a single record, like this:
>
> foreach($findResult['data'] as $key => $value);
> $field1 = $value['field1'][0];
> $field2 = $value['field2'][0];
> $field3 = $value['field3'][0];
>
> ... and so on. There's no need for a looping structure since your  
> foundset only has a single record. I use it all the time...
>
> Also, you can use that same method if you want to retrieve the last  
> record in the foundset. Opposite to FileMaker, which always shows  
> you the first record in a foundset after a FIND, this method  
> returns the last record.
>
> So if you get 10 records returned, and use that method above,  
> you'll retrieve the values in the last record of the foundset,  
> based on the sort rules you may have used.
>
> Bob Patin
> Longterm Solutions
> bob at longtermsolutions.com
> 615-333-6858
> http://www.longtermsolutions.com
> iChat: bobpatin
> AIM: longterm1954
> FileMaker 9 Certified Developer
> Member of FileMaker Business Alliance and FileMaker TechNet
> --------------------------
> FileMaker hosting and consulting for all versions of FileMaker
> PHP • Full email services • Free DNS hosting • Colocation • Consulting
>
>
> On Sep 22, 2008, at 6:03 PM, Leo R. Lundgren wrote:
>
>>
>> 23 sep 2008 kl. 00.56 skrev Bob Patin:
>>
>>> Jonathan,
>>>
>>> You can use this:
>>>
>>> foreach($findResult['data'] as $key => $value);
>>>
>>> Notice the semicolon...
>>
>> Bob; What is this syntax for? I've never seen it being used  
>> before. The only thing I can think of it accomplishing is to set  
>> $key and $value to the values of the very last item in the array?
>>
>> -|
>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list


-|



More information about the FX.php_List mailing list