How to define PHP variables _php tutorial

Source: Internet
Author: User
Definition of a variable
Types of ⚑ variables
Use of ⚑ variables
Variables are objects that can be constantly changed in memory, we can think of memory as a street, there are many households in the street, each tenant will have their own house number, which is like an in-memory address (C language is often referred to a concept, here we do not discuss more), For one of the tenants we can say is 1th building 1th, can also be said to be Wang Xiaoming home, with a name instead of an address. and Wang Xiaoming home at some moment there are a few people is a change in the volume, there may be 3 people at noon, only 1 people in the afternoon, there are 5 people in the evening. Therefore, for an address in memory we want to reference, you can also call it a, or area. This is the variable.
Here's a demonstration of the variables in PHP.
Use "$" to add a variable name, such as $ A, $var _name.
The declaration of variables in PHP note 3 points:
, variable names can only be composed of English letters (A-Z,A-Z), Numbers (0-9), and underscores.
, the variable names in PHP are case-sensitive, that is, $var_name and $var_name are two different variables.
, a variable declaration, or an assignment must end with a semicolon (;).
The type of variables in PHP is very simple, generally do not need to use the keyword declaration, in the form of an assignment can be.
For example, declare an integer variable
$x = 100;
Declaring a character-type variable
$str = "Iam a chinese!";
Declaring a Boolean variable
$bool =true;
Use variables in your Web pages.
example, we want to display a sentence in the webpage, "I am a Chinese", "I am 28 years old".
Copy CodeThe code is as follows: $str = "I am a Chinese";
$age = 28;
Echo$str. "
";
echo "I this year". $age. " Years old ";
?>

Line 1th " 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, age, and assigns it a value of 28.
Line 4th Echo$str. "
";, Echo is the keyword that is used in PHP to output, and the content following it indicates that it needs to be output, that is, $STR is the variable that needs to be output, and after $str." is a tag used to concatenate multiple variables or variables with general content, where a newline symbol is shown after $str.

5th line echo "I this year". $age. " old "; This sentence is interpreted in the same way as the 4th line. "I am 28 years old this year," The sentence divided into 3 parts, "I this year" is the first part, 28 is replaced with variable $age, "old" is the 3rd part, they use. To connect.
The 6th line of "?>" means the PHP file is over.
At this point, Task 1 ends. By now, you can express what you want to say in PHP in the form of a Web page.

http://www.bkjia.com/PHPjc/321184.html www.bkjia.com true http://www.bkjia.com/PHPjc/321184.html techarticle Variables that use variables that define variables of variable type are the objects that exist in memory that can be constantly changed, we can think of memory as a street, there are many live in the 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.