Page 43 - Open Soource Technologies 304.indd
P. 43
Unit 2: Language Basics
// major shortcut Notes
$newVar = $myFirstCookie;
// moderate shortcut
$newVar = $_COOKIE [“myFirstCookie”];
// full version
$newVar = $HTTP_COOKIE_VARS [“myFirstCookie”];
Currently there is a push to make the second version of the new standard, since it is shorter and
thus makes the code easier to read. Especially when doing a great deal of cookie or form data
processing.
Give the process for using environment variable in PHP code.
2.4 Expressions and Operators
The basic building block of a program is the statement. A statement is a piece of code that does
something. Statements themselves are made up of expressions and operators. An expression is a
piece of code that evaluates to some value. An operator is a code element that acts on an expression
in some way. For instance, a minus sign can be used to tell the computer to delete the value of
the expression after it from the expression before it.
Since there is not really much to understand about expressions except for the assembly of them
into compound expressions and statements using operators, we are going to look at the operators
used to turn expressions into more complex expressions and statements.
This takes a look at operators and how to use them to form complex expressions and statements.
It starts with a general overview and then proceeds to look at different types of operators and
their uses.
Statements themselves are made up of expressions and operators. An expression is a piece of code
that evaluates to some value. The simplest form of expression is a literal or a variable. A literal
evaluates to itself. A variable evaluates to the value assigned to it.
For instance, any of the following are valid expressions:
“abc”
123
$a
$x == 7
($a + $b) / $c
Although a literal or variable may be a valid expression, they are not expressions that do anything.
The way you get expressions to do things is by linking simple expressions together with operators.
An operator combines simple expressions together into more complex expressions by creating
relationships between the simple expressions that can be evaluated. For instance, if the relation you
want to establish is the cumulative joining of two numeric values together, you could write 6 + 7.
The numbers 6 and 7 are each valid expressions. The equation 6 + 7 is also a valid expression,
whose value, in this case, happens to be 13.
LOVELY PROFESSIONAL UNIVERSITY 37