PHP variable definition method _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
PHP variable definition method. Variable definition variable type variable usage variable is an object that can be constantly changing in the memory. we can think of the memory as a sub-district with many variable definitions in the sub-district.
⚑Variable type
⚑Use of variables
Variables are objects that can be constantly changed in the memory. we can think of the memory as a sub-district. There are many tenants in the street, and each household has its own house number, this is like the address in the memory (a concept often mentioned in C language, which we will not discuss here). for one of the tenants, we can say that we are building 1, it can also be said to be Wang Xiaoming's house, replacing an address with a name. At the moment, several people in Wang Xiaoming's family are changing. There may be three people at noon, only one person in the afternoon, and five people at night. Therefore, we need to reference an address in the memory, which can also be called A or area. This is the variable.
The following describes the declaration of variables in PHP.
Add a variable name with "$", such as $ a and $ var_name.
Note the following three points for variable declaration in PHP:
, Variable name can only consist of English letters (A-Z, a-z), numbers (0-9) and underscores.
In PHP, the variable names are case sensitive, that is, $ VAR_NAME and $ var_name are two different variables.
, A variable declaration or value assignment must end with a semicolon (;).
In PHP, the type of variables is very simple. Generally, you do not need to use keywords to declare them. you can simply use values.
For example, declare an integer variable
$ X = 100;
Declare a struct variable
$ Str = "Iam a Chinese !";
Declare a Boolean variable
$ Bool = true;
Use variables on the webpage.
For example, we want to display a sentence on the webpage: "I am a Chinese". "I am 28 years old ".

The code is as follows:

$ Str = "I am a Chinese ";
$ Age = 28;
Echo $ str ."
";
Echo "I am". $ age. "years old ";
?>


1st rows" Row 2nd $ str = "I am a Chinese"; defines a string variable str with the value "I am a Chinese ".
Row 3rd $ age = 28; defines an integer variable age and assigns it a value of 28.
Line 4 echo $ str ."
";, Echo is the keyword used for output in PHP. the content following it indicates that the output is required, that is, $ str is the variable to be output, after $ str. is used to connect multiple variables or variables with the mark of the general content. here it indicates that $ str will display a line break symbol
.
Line 5 echo "I am". $ age. "years old";, this sentence is understood in the same way as line 3. The "I am 28 years old" sentence is divided into three parts: "I am this year" is the first part, 28 is replaced by the variable $ age, and "I am" is part 1, use..
Row 3 "?> "Indicates that the php file has ended.
So far, task 1 has ended. Now, you can express what you want to say on the webpage in the form of PHP.

The usage variable of the variable type is an object that can be constantly changed in the memory. we can think of the memory as a sub-district, and there are many sub-streets...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.