Web Programming with PHP

9 Variables, constants, expressions, and operators


Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

PHP supports eight primitive types:

// Integers: decimal, octal or hexadecimal
$Var = 123;

// Floating point
$Var = 1.3e4;

// Arrays or vectors
$Var[2] = 123;

// Text Strings
$Var = "A Text String\n";

// Objects
$Var = new oMyClass();

The scope of a variable is the context within which it is defined.


A constant is an identifier (name) for a simple value. That value cannot change during the execution of the script. A constant is case-sensitive by default. By convention, constant identifiers are always uppercase

There are two built-in constants, TRUE and FALSE (case-insensitive), which representthe two possible boolean values.


Expressions are the most important building stones of PHP. The most basic forms of expressions are constants and variables.

A very common type of expressions are comparison expressions. These expressions evaluate to either FALSE or TRUE. These expressions are most commonly used inside conditional execution, such as if statements.


Table with operators in PHP