A third and more elegant looping technique is the forloop. The for loop is a little
bit more elegant, but takes a little bit more to master. The for loop allows you
to actually declare the variable you want to use as your incrementer or your
condition inside its conditional statement. So in the parentheses, I'm going to
use I as my incrementer. The next thing you declare is your condition that you
want to loop based upon. Well, as long as the I is less than 20. And then the
third thing is your actual incrementation. So I plus plus. So here you can see
that right off the bat with my parentheses I'm able to take care of several
lines of code from the previous loop statements. I can declare the variable and
instantiate its value. I can specify the conditions by which I want to keep
looping and then specify my incrementation of my incrementer value. Then all I
need to do is perform the code that I want to perform each time I loop. And I no
longer need the declaration for X up above. You can always substitute the items
up here in your conditional portion based upon values from your programming
logic or from your FileMaker database. This is a very simple example of the for
loop, but as you can see, once you master how to use it, it can become much more
streamlined than the other looping functions. The last looping technique I'll
show you is the foreach loop. The foreach loop is only used for going through
all the elements of an array and outputting either the value of the element or
the key and the value. I won't spend too much time on the foreach loop right now
because we haven't really discussed arrays. But I will build a little array and
just show you how it outputs it. We'll foreach each one of the elements in the
array and then we'll echo out the output. So here I've created an array with for
different values and then I used the foreach loop to go through all the elements
in the array and output their value. There are other things that you can do with
the for each looping statement that I won't get into right now but later on when
we talk about arrays we'll be using foreach much more often. When you're
programming using FileMaker's API for PHP, you'll be dealing with a lot of
arrays and the for each loop will be one of the main functions that you use in
your PHP programming. This concludes our lesson on controlling the flow of logic
in your PHP application by using the different repetition or looping techniques
in PHP.
FileMaker 9 and PHP
Lance Hallberg
US$ 99.95
8 hours - 107 Movies
Win Vista XP 2000,ME. Mac OS X
Ground / 2 day / Next Day
33786
258 In Stock
Apex Web Media ( Hyperteach ) P.O Box 398 Bolton BL7 9YS, United Kingdom. Tel: +44 (0) 1204 592071 Fax: +44 (0) 1204 592092 Email:
Apex Web Media ( Hyperteach ) 600 17th Street, Suite 2800, Denver CO 80202 Tel: Toll free 1866 402 1903 (USA) / 434 878 4158 Fax: 1 207 433 4356 Email: