Download Document 7760007

yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Control Structures
Conditions can be more complex than a single comparison for equality. Recall
that we modified welcome1.php to take a first and last name. If we wanted to
display a special message only for a particular person, we'd have to check the
values of both names (welcome6.php):
$firstname = $_REQUEST['firstname'];
$lastname = $_REQUEST['lastname'];
if ( $firstname == 'Kevin' and $lastname == 'Yank' ) {
echo( 'Welcome, oh glorious leader!' );
} else {
echo( "Welcome to my Website, $firstname $lastname!" );
This condition will be true if and only if $firstname has a value of Kevin and
$lastname has a value of Yank. The word and in the above condition makes the
whole condition true only if both of the comparisons evaluate to true. Another
such operator is or, which makes the whole condition true if one or both of two
simple conditions are true. If you're more familiar with the JavaScript or C forms
of these operators (&& and || for and and or respectively), they work in PHP as
We'll look at more complicated comparisons as the need arises. For the time being,
a general familiarity with the if-else statement is sufficient.
Another often-used PHP control structure is the while loop. Where the if-else
statement allowed us to choose whether or not to execute a set of statements
depending on some condition, the while loop allows us to use a condition to
determine how many times we'll execute repeatedly a set of statements. Here's
what a while loop looks like:
while ( condition ) {
// statement(s) to execute over
// and over as long as condition
// remains true
The while loop works very similarly to an if-else statement without an else
clause. The difference arises when the condition is true and the statement(s) are
executed. Instead of continuing the execution with the statement that follows
the closing brace (}), the condition is checked again. If the condition is still true,
then the statement(s) are executed a second time, and a third, and will continue
to be executed as long as the condition remains true. The first time the condition
evaluates false (whether it's the first time it's checked, or the one-hundred-and-
Document related concepts

Object-relational impedance mismatch wikipedia, lookup

Microsoft SQL Server wikipedia, lookup

Clusterpoint wikipedia, lookup

Open Database Connectivity wikipedia, lookup

Relational model wikipedia, lookup

Database model wikipedia, lookup