Variables in php

Variables in PHP are identifiers prefixed with a dollar sign ($).

For example:


A variable may hold a value of any type. There is no compile-time or runtime type checking on variables. You can replace a variable’s value with another of a different type:

$what = “Fred”;
$what = 35;
$what = array(“Fred”, 35, “Wilma”);

There is no explicit syntax for declaring variables in PHP. The first time the value of a variable is set, the variable is created. In other words, setting a value to a variable also functions as a declaration. For example, this is a valid complete PHP program:

$day = 60 * 60 * 24;
echo “There are {$day} seconds in a day.\n”;
There are 86400 seconds in a day.

A variable whose value has not been set behaves like the NULL value:

if ($uninitializedVariable === NULL) {
echo “Yes!”;

Leave a Comment