Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Variables are the most basic way of storing and keeping track of information in a program. Throughout this course, we'll be covering the 4 scalar, or base variable types that are supported in PHP: boolean, integer, float and string.
Variables in PHP
The type of a variable is not usually set by the programmer; rather, it is decided at runtime by PHP depending on the context in which that variable is used. PHP supports eight primitive types.
- Four scalar types:
- boolean
- integer
- float (floating-point number, aka double)
- string
- Two compound types:
- array
- object
- And finally two special types:
- resource
- NULL
Why variables can't start with a number.
This is a standard for all programming languages. Primarily to standardize between languages whose variables do not start with a symbol. It is easier for a compiler to make an assumption that if a token begins with a number, it is most likely a numeric value rather than a variable name and any non-numeric characters that are a part of the token would assist in determining the numeric type or number system (12e5 is a valid number).
You need to sign up for Treehouse in order to download course files.
Sign up