PHP Variables

PHP Variables
What are variables?
Variables are names that store values like strings or numbers. Their values can change at any point in the whole program. Since the value is variable, they are known as variables.

Declaring Variables
Most programming languages require variables to be declared. This is done to ensure what data type it is and hence, what type of data it can store. Each programming language has its own set of data types. In case of PHP, the variables do not have to be declared. PHP automatically converts the variable to the correct data type, depending on how they are set. Hence, PHP is known as a loosely typed language. A strongly typed language requires you to declare the variables in the beginning of the program. Assigning values to variables in PHP
Variable names begin with a dollar sign ($). Lets have a look at the following statements:

$worda = “gnulamp”;
$wordb = “php tutorial”;
$website_url = “http://www.gnulamp.com”;
$word=”$worda $wordb”;
$num1 = 10;
$num2 = 20;
$sum = $number1 + $number2;

Some rules to remember

* A variable name must start with a letter or an underscore (_).
* A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ ).
* A variable name should not contain spaces. If needed, underscores should be used.
* Variabe names are case sensitive.
* String constants are enclosed in quotes (“).
* Numeric values are assigned as it is.

If you have found my website useful, please consider buying me a coffee below 😉