An expression is the basic building block of the language.
Anything with a value can be thought of as an expression.
Examples include:
5 5+5 $a $a==5 sqrt(9)
By combining many of these basic expressions, you can
build
larger, more complex expressions.
Note that the echo statement we've used in numerous
examples cannot be part of a complex expression because
it does not have a
return value. The print statement, on
the other hand, can be used as
part of complex expression
-- it does have a return value. In all other
respects, echo
and print are identical: they output data.
Expressions are combined and manipulated using operators.
The control structures in PHP are very similar to those
used by
the C language. Control structures are used to
control the logical flow through
a PHP script. PHP's control
structures have two syntaxes that can be used
interchangeably.
The first form uses C-style curly braces to enclose statement
blocks, while the second style uses a more verbose syntax
that includes explicit
ending statements. The first style is
preferable when the control structure is
completely within
a PHP code block. The second style is useful when the
construct spans a large section of intermixed code and
HTML. The two styles are
completely interchangeable,
however, so it is really a matter of personal
preference
which one you use.
The if statement is a standard conditional found in
most languages.
Here are the two syntaxes for the if statement:
if(expr) { if(expr): statements statements } elseif(expr) { elseif(expr): statements statements } else { else: statements statements } endif;
The if statement causes particular code to be executed
if
the expression it acts on is true. With the first form,
you can omit
the braces if you only need to execute a
single statement.