PHP Variables

Varible is a memory store where values are stored. All the variables in PHP start with $ sign. Therefore, define variable as follows:

 

<?php

$variable = "Hello World!";

$number = 1;

$result = 1 + $number;

print $result;

?>

PHP variables does not require variables to be declared before being used.

The naming convention to PHP follows following rules:

1. PHP variables are alphanumeric and can include characers(a-z, A-Z), underscore and numbers (0-9).

2. PHP variables can be separated with underscore (_). Normally, you would write a variable as $first_name, $second_name. You can also follow java like convention when defining a variable as $firstName, $secondName with second part starting with a capital letter.