O'Reilly logo

Core PHP Programming: Using PHP to Build Dynamic Web Sites by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Assigning Values to Variables

The equal sign (=) is used to set the value of a variable. This is called the assignment operator. On the left side of the assignment operator is a variable that will receive a value. On the right side is an expression, which could be a simple string constant or a complex combination of operators, variables, and constants.

When you assign a value to a variable, its type will change to fit the type of data you put into it. This is in contrast to C, which tries to convert values to fit the type of the variable. Assigning an integer to a variable that previously held a string converts the variable to an integer.

Table 2.2. Examples of Variables Assignments
String ConstantsInteger ConstantsDouble Constants
$myString = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required