Variable is declared using a $ sign followed by the variable name. A variable stores a value of any type. e.g., a string, a number, an array, or an object.
When defining a variable, you need to follow these rules:
- The variable name must start with the dollar sign ($).
- The first character after the dollar sign ($) must be a letter (a-z) or the underscore ( _ ).
- The remaining characters can be underscores, letters, or numbers.
Declaring string, integer, and float
Example - variable declaration
Sum of two variables
Example - sum of variables
In PHP, variable names are case sensitive. So variable name "color" is different from Color, COLOR, COLor etc.