Thursday, September 30, 2010

Operators and Expressions in PHP

You can now assign data to variables. You can even investigate and change the data
type of a variable. A programming language isn't very useful, though, unless you
can manipulate the data you can store. Operators are symbols that make it possible
to use one or more values to produce a new value. A value that is operated on by an
operator is referred to as an operand.
NEW
TERM
An operator is a symbol or series of symbols that, when used in
conjunction with values, performs an action and usually produces a
new value.
NEW
TERM
An operand is a value used in conjunction with an operator. There
are usually two operands to one operator.
Let's combine two operands with an operator to produce a new value:
4 + 5
4 and 5 are operands. They are operated on by the addition operator (+) to produce
9. Operators almost always sit between two operands, though you will see a few
exceptions later in this hour.
The combination of operands with an operator to manufacture a result is called an
expression. Although most operators form the basis of expressions, an expression
need not contain an operator. In fact in PHP, an expression is defined as anything
that resolves to a value. This includes integer constants such as 654, variables such
as $user, and function calls such as gettype(). The expression (4 + 5), therefore is
an expression that consists of two further expressions and an operator.
NEW
TERM
An expression is any combination of functions, values, and
operators that resolve to a value. As a rule of thumb, if you can use
it as if it were a value, it is an expression.

Now that we have the principles out of the way, it's time to take a tour of PHP4's
more common operators.

No comments:

Post a Comment