The definition method of PHP variable _php Foundation

Source: Internet
Author: User
Tags php code php form
The definition of a variable
Type of ⚑ variable
Use of ⚑ variables
Variables are objects that exist in memory that can be constantly changed, we can think of memory as a street, there are many tenants in the street, each tenant will have their own house number, this is like the address in memory (C language is often mentioned in a concept, we do not have much discussion here), For one of the tenants, we can say that the number 1th building 1th, can also be said to be Wang Xiaoming home, with a name to replace an address. and Wang Xiaoming home at a certain moment a few people is a change in volume, there may be 3 people at noon, only 1 in the afternoon, 5 people in the evening. Therefore, for an address in memory we want to refer to it, or we can call it a, or area. That's the variable.
Here's a demonstration of the variable declaration in PHP.
With "$" plus a variable name, such as $a, $var _name.
Declaration of variables in PHP note 3 points:
, variable names can only consist of English letters (A-Z,A-Z), Numbers (0-9), and underscores.
, the variable name in PHP is case-sensitive, that is, $var_name and $var_name are two different variables.
, a variable declaration or assignment must end with a semicolon (;).
The type of variable in PHP is very simple, in general, do not need to use the keyword declaration, the form of the assignment can be expressed.
For example, declare an integer variable
$x = 100;
Declaring a character variable
$str = "Iam a chinese!";
Declaration of a Boolean variable
$bool =true;
Use variables in Web pages.
For example, we want to show a word in the Web page, "I am a Chinese", "I am 28 years old."
Copy Code code as follows:
<?php
$str = "I am a Chinese";
$age = 28;
Echo$str. " <br> ";
echo "I am this year". $age. " Years old ";
?>

Line 1th "<?php", this is the beginning of a PHP file tag, indicating that from the start down is the PHP code.
Line 2nd $str= "I am a Chinese"; Defines a string variable, str, whose value is "I am a Chinese".
Line 3rd $age=28, defines an integer variable of age, and assigns it a value of 28.
Line 4th Echo$str. " <br> "; Echo is the keyword that is used in PHP to output, and what follows is the content that needs to be output, that is, the $STR is the variable that needs to be output, and after $str. is the tag used to connect multiple variables or variables with general content, indicating here that $ After str, a newline symbol <br> is displayed.
5th line echo "I am this year". $age. " years old "; The sentence is understood in the same way as line 4th. The "I am 28 years old" This sentence is divided into 3 parts, "I this year" is the first part, 28 is to use variable $age to replace, "old" is the 3rd part, they used between. To connect.
Line 6th "?>" means that the PHP file is over.
At this point, Task 1 ends. By now, you can express your words in PHP form on the Web page.

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.