A Variable is a small temporary memory area use to store value, value can be number, decimal number, text, date etc. Variables act as a "containers" for storing information.
Rules to declare a PHP variable are:
A variable starts with the $ sign, followed by the variable name.
A variable name can contain numbers, letters and underscores.(A-Z, a-z, 0-9, and _ )
A variable name must begin with a letter or the underscore character.
A variable name cannot start with a number and cannot contain special characters.
Variable names are case-sensitive ($age and $AGE are different variables)
PHP has a total of 8 Data Types which we use to declare variables:
$txt = "Programming is Fun!"; //variable with string value $a = 5; // variable with integer value $b = 10.5; //variable with float value $_city = "Delhi"; //variable with underscore character $marks2 = 50; //variable name contain number
$2marks = 50; //variable name cannot contain number. $@city = "Delhi"; //variable name cannot contain special characters like @. $area of circle = 50.5; //variable name cannot contain spaces.A variable can have a short name (like a and b) or a more descriptive name (like name, age, areaofcircle, total_marks).