PHP Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 3.00

Variables, References, and Constants

This chapter provides tutorial notes and example codes on PHP variables, references, and constants. Topics include how to name variables; assigning data values to variables; creating the reference of a variable; using variable variable names; using string expressions as variable names; defining constant names to values; retrieving the value from a constant.

Variables and Assignment Operations

References and Variables

Variable Variable Name - Name Variables with Expressions

Constant and define() Function

Conclusion:

  • PHP variables are typeless. Values of different data types can be assigned to the same variable.
  • PHP variable names starts with $ sign.
  • & operator returns the reference of a variable.
  • The reference of a variable can be assigned to a new variable to make an alias to the original variable.
  • A variable name can represented as a string expression. This is called variable variable name.
  • Functions define() defines a constant with the constant name and the constant value.
  • Only scalar data type values can be used as constant values.

Dr. Herong Yang, updated in 2009
Variables, References, and Constants