PHP Variables

PHP Variables

Variable is used to store the value in php. Value can be string, numbers etc. Variable does not need to be declared before adding a value to it. PHP automatically converts the variable to the correct data type, according to value.

Declaring PHP Variable

In PHP, a variable starts with the $ sign, followed by the name of the variable.

<?php
$text = "This is an variable example";
$a = 50;
$b = 50.5;
?>

PHP Variable Declaration rules

PHP variables must start with letter or underscore only. A variable name cannot start with a number or any special symbols. Php variable name can contain only alpha-numeric characters and underscores. Variable names are case-sensitive for example $name and $NAME both are two different variables in PHP.