Specifications

This is the string concatenation operator and is used to add strings (pieces of text) together.
You will often use it when sending output to the browser with echo. This is used to avoid hav-
ing to write multiple echo commands.
You could alternatively write
echo “$tireqty tires<br>”;
This is equivalent to the first statement. Either format is valid, and which one you use is a mat-
ter of personal taste.
Variables and Literals
The variable and string we concatenate together in each of the echo statements are different
types of things. Variables are a symbol for data. The strings are data themselves. When we use
a piece of raw data in a program like this, we call it a literal to distinguish it from a variable.
$tireqty is a variable, a symbol which represents the data the customer typed in. On the other
hand, tres” is a literal. It can be taken at face value.
Well, almost. Remember the second example previously? PHP replaced the variable name
$tireqty in the string with the value stored in the variable.
There are actually two kinds of strings in PHPones with double quotes and ones with single
quotes. PHP will try and evaluate strings in double quotes, resulting in the behavior we saw
earlier. Single-quoted strings will be treated as true literals.
Identifiers
Identifiers are the names of variables. (The names of functions and classes are also
identifierswell look at functions and classes in Chapters 5 and 6.) There are some
simple rules about identifiers:
Identifiers can be of any length and can consist of letters, numbers, underscores, and dol-
lar signs. However, you should be careful when using dollar signs in identifiers. Youll
see why in the section called, Variable Variables.
Identifiers cannot begin with a digit.
In PHP, identifiers are case sensitive. $tireqty is not the same as $TireQty. Trying to
use these interchangeably is a common programming error. PHPs built-in functions are
an exception to this ruletheir names can be used in any case.
Identifiers for variables can have the same name as a built-in function. This is confusing,
however, and should be avoided. Also, you cannot create a function with the same identi-
fier as a built-in function.
PHP Crash Course
C
HAPTER 1
1
PHP CRASH
COURSE
21
03 7842 CH01 3/6/01 3:39 PM Page 21