Chapter 2. Variables
In this lesson you will learn how to assign values to variables in PHP and use them in some simple expressions.
Understanding Variables
Variables—containers in which values can be stored and later retrieved—are a fundamental building block of any programming language.
For instance, you could have a variable called number
that holds the value 5
or a variable called name
that holds the value Chris
. The following PHP code declares variables with those names and values:
$number = 5; $name = "Chris";
In PHP, a variable name is always prefixed with a dollar sign. If you remember that, declaring a new variable is very easy: You just use an equals symbol with the variable name on the left and the value you want it to take on the right. ...
Get Sams Teach Yourself PHP in 10 Minutes 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.