Home
   <<
PHP Control Structures
Post / Update: 14/09/10
Views: 2566

Structure, as its name implies, determines how a document or a particular composition are organized. In the case of control structures, it determines how flow the reading and processing in programming languages.

In the case of PHP, there are three control structures:
1 - Sequence structure
2 - Selection structure
3 - Repetition structure - Loops

1 - In the sequence structure, the commands are interpreted as they are read. This is a natural feature of the language.

<?php
echo ‘Hi, ’;
echo ‘how are you? <br />’;
echo ‘It’s ok?’;
?>


2 - In selection structures are defined some conditions for the processing occurs according to the need of the programmer.
Exists in PHP 4 selection structures: if, else, elseif (or else if) and switch.
If verifies if a condition is true. Elseif verifies a new condition. Else is used when none of the above conditions is true, and Switch, tests different conditions.

<?php
$var1 = 1;
If ($var1==0){
echo ‘0’;
} elseif ($var1==1){
echo ‘1’;
} else {
echo ‘This value is greater than 0 and 1’;
}
?>


3 - Repetition structures - Loops
What is a loop?
Loop is a repetition in the processing also known as iteration.
For what serves the loop?
Loops are used to make checks on databases, checks on variables submitted through forms and checks on arrays, incrementing of variables, etc..

There are 4 types of loop in php:
For
Foreach
While
Do while

For and while runs as a certain condition is true.
Do while runs once and continues to execute if the condition is true, otherwise stops the execution.
Foreach is used to scan arrays.

For any doubts, you can access blogs, forums and the PHP page: http://www.php.net.
 PHP Course

Last post

Post/Update: 14/09/10

Structure, as its name implies, determines how a document or a particular composition are organized. In the case of control structures, it determines how flow the reading and processing in programming languages.

In the case of PHP, there are three...
 << See more



 Estou Hospedado na EazzyHost Design | Illustration | Programming