Variable is a character identifier that is assigned a value. In PHP variables are determined using the dollar sign (, $ ‚) before said identifier. In PHP you must not first initialize a variable. The variable is initialized (that is reserved for her a certain area in memory) during its first use. Variable names must begin with a letter (large or small) or „underscore” (bottom line -, _ ‚) and further can consist of any number of letters, numbers and characters above ASCII 127. When variable names is respected insensitive – variables $ test and $ test are two different variables. Here is an example of assigning values to variables and use them in the command echo:

<? Php

$ Name = 1;                                   // Variable „name” is assigned a numerical value of 1

$ Second_name = „text”;                    // Variable „second_name” is assigned the                                                                                      string „Text”

$ third_name = $ name;                                 // Variable „third_name” assigned
// Is the value of the variable „name”

echo „This is $ second_name”;                 // Should display the message „This is text”

echo ‚$ second_name’;                        // Should display the message „$second_name”

echo $ name;                                                                 // You should see the number 1



The parameter for the echo command can be given both in quotation marks and apostrophes. However, these parameters are not themselves synonymous. If quotation marks variables contained between them are converted to their value, and if it stays apostrophes their name.

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close