$variable-name=value; A variable starts with the $ sign, followed by the name of the variable. A variable name must start with a letter or the underscore character. A variable name cannot start with a number. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).
Variables are used to store data, like string of text, numbers, etc. Variable values can change over the course of a script. Here're some important things to know about variables: In PHP, a variable does not need to be declared before adding a value to it. PHP automatically converts the variable to the correct data type, depending on its value. After declaring a variable it can be reused throughout the code. The assignment operator (=) used to assign value to a variable. In PHP variable can be declared as: $var_name = value;
Starting with $ symbol and then variable_name, ex: $x the followed by an assignment operator '=' and then the value of the variable. That's how we declare a variable
$variable_name = "SomeValue";
More:
Its good to know that you've started learning PHP and wanted to know more about it. Before talking about how to declare a variable we must have an idea what a variable is, what it does and why we use it.
Variable in any programming language is used to store value (The value can be anything like a number, a String, or a JSON response you've got from your web server). The importance of a variable is that once you store a value in it you can access the variable to use the value.
Ex: Suppose you have to make a million dollar program which will perform addition of number in PHP, which is coming from the beautiful HTML form you've placed on your website. The peace of code you would use is $_GET['number1'] and then $_GET['number2'] after this addition will be $_GET['number1'] + $_GET['number2'].
Suppose now you want to check that the user has only entered a number and not a String and also you've to perform multiplication, division, subtraction then there will be more code and the readability of code will become worse.
Note that it's a good programming practice to use variable name as an indication of what it does. For example, in the above code, $x represents the first number you know it and I know it. But when it will be used by someone else how he will come to know that it represents the first number so you should use $num1 instead of $x.
Creating (Declaring) PHP Variables In PHP, a variable starts with the $ sign, followed by the name of the variable: Example <?php $txt = "Hello world!"; $x = 5; $y = 10.5; ?> After the execution of the statements above, the variable $txt will hold the value Hello world!, the variable $x will hold the value 5, and the variable $y will hold the value 10.5. Note: When you assign a text value to a variable, put quotes around the value. Note: Unlike other programming languages, PHP has no command for declaring a variable. It is created the moment you first assign a value to it. Think of variables as containers for storing data. PHP Variables A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for PHP variables: A variable starts with the $ sign, followed by the name of the variable A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive ($age and $AGE are two different variables) Remember that PHP variable names are case-sensitive!