3.1 The WHILE Loop
The WHILE loop is one of the most useful commands in
PHP. It is also quite easy to set up and use. A WHILE
loop will execute a piece of code until a certain condition
is met
Example :
$i = 5;
$x = 0;
while ($x < $i) {
echo "Looping.....";
++$x;
}
|
The first two lines are just initializing the variables,
variable $i inidicate the number of times you want to
repeat the code. The $x variable is the one which will
count the number of times the code has been executed.
After these is the WHILE line. This tells the computer
to repeat the code while $x is less than $i (or to repeat
it until $x is equal to $i). This is followed by the code
to be executed which is enclosed in { }.
3.2 Arrays
Arrays are common to many programing languages. They
are special variables which can hold more than one value,
each stored in its own numbered 'space' in the array.
Setting Up An Array
$names[0]
= 'Peter';
$names[1] = 'Paul';
$names[2] = 'Mary';
$names[3] = 'Issac';
$names[4] = 'David'; |
Reading From An Array
Reading from an array is just the same as putting information
in. All you have to do is to refer to the array and the
number of the piece of data in the array. So if I wanted
to print out the third name I could use the code:
echo "The third name is $names[2]";
Which would output:
The third name is Mary
Locating An PHP Web Hosting Provider:
iPowerWeb.com
is one of the best choice for PHP web hosting. It has
all of the basic components needed for operating most
websites. And they did it at $7.95 per month.