Specifications

User-Declared Variables
You can declare and use your own variables in addition to the variables you are passed from
the HTML form.
One of the features of PHP is that it does not require you to declare variables before using
them. A variable will be created when you first assign a value to itsee the next section for
details.
Assigning Values to Variables
You assign values to variables using the assignment operator, =. On Bobs site, we want to
work out the total number of items ordered and the total amount payable. We can create two
variables to store these numbers. To begin with, well initialize each of these variables to zero.
Add these lines to the bottom of your PHP script:
$totalqty = 0;
$totalamount = 0.00;
Each of these two lines creates a variable and assigns a literal value to it. You can also assign
variable values to variables, for example:
$totalqty = 0;
$totalamount = $totalqty;
Variable Types
A variables type refers to the kind of data that is stored in it.
PHPs Data Types
PHP supports the following data types:
IntegerUsed for whole numbers
DoubleUsed for real numbers
StringUsed for strings of characters
ArrayUsed to store multiple data items of the same type (see Chapter 3, Using
Arrays)
ObjectUsed for storing instances of classes (see Chapter 6, Object Oriented PHP)
PHP also supports the pdfdoc and pdfinfo types if it has been installed with PDF (Portable
Document Format) support. We will discuss using PDF in PHP in Chapter 29, Generating
Personalized Documents in Portable Document Format.
Using PHP
P
ART I
22
03 7842 CH01 3/6/01 3:39 PM Page 22