CHAPTER 2

image

Variables

Variables are used for storing data, such as numbers or strings, so that they can be used multiple times in a script.

Defining variables

A variable starts with a dollar sign ($) followed by an identifier , which is the name of the variable. A common naming convention for variables is to have each word initially capitalized, except for the first one.

$myVar;

A value can be assigned to a variable by using the equals sign, or assignment operator (=). The variable then becomes defined or initialized .

$myVar = 10;

Once a variable has been defined it can be used by referencing the variable’s name. For example, the value of the ...

Get PHP Quick Scripting Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.