Variables in PHP

Variables are used for storing values, like text strings, numbers or arrays. When a variable is declared, it can be used over and over again in your script. All variables in PHP start with a $ sign symbol. The correct way of declaring a variable in PHP:

 $var_name = value;

New PHP programmers often forget the $ sign at the beginning of the variable. In that case it will not work.

Let’s try creating a variable containing a string, and a variable containing a number:

 <?php $txt="Hello World!"; $x=16; ?>

Some exampol

$foo = 'Bob';              // Assign the value 'Bob' to $foo
$bar = &$foo;              // Reference $foo via $bar.
$bar = "My name is $bar";  // Alter $bar...
echo $bar;
echo $foo;                 // $foo is altered too.

Default values of uninitialized variables

// Unset AND unreferenced (no use context) variable; outputs NULL

// Boolean usage; outputs 'false' (See ternary operators for more on this syntax)
echo($unset_bool ? "true\n" : "false\n");

// String usage; outputs 'string(3) "abc"'
$unset_str .= 'abc';

// Integer usage; outputs 'int(25)'
$unset_int += 25; // 0 + 25 => 25

// Float/double usage; outputs 'float(1.25)'
$unset_float += 1.25;

// Array usage; outputs array(1) {  [3]=>  string(3) "def" }
$unset_arr[3] = "def"; // array() + array(3 => "def") => array(3 => "def")

// Object usage; creates new stdClass object (see
// Outputs: object(stdClass)#1 (1) {  ["foo"]=>  string(3) "bar" }
$unset_obj->foo = 'bar';

Thank You

Help from w3 schools