[FX.php List] A nagging question: Foreach
Derrick Fogle
derrick at fogles.net
Mon Sep 22 17:25:22 MDT 2008
I must be a blazing goofball... I never use a foreach loop if I expect
only one record. If I only expect one record, I always check the
foundcount first. If that's true, then I just extract the key
[ $datakey = key($findResult['data']); ] and access the array
structure directly with the key. But blegh, it's certainly more code
to do so.
On Sep 22, 2008, at 6:15 PM, Bob Patin wrote:
> 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
Derrick
More information about the FX.php_List
mailing list