In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article shares with you the content of the sample analysis of PHP syntax and PHP variables. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
PHP syntax
The PHP script is executed on the server and the pure HTML results are sent back to the browser.
.
Basic PHP syntax
PHP scripts can be placed anywhere in the document.
PHP script to end, syntax:
The default file extension for PHP files is ".php".
PHP files usually contain HTML tags and some PHP script code.
Each line of code in PHP must end with a semicolon. A semicolon is a delimiter that distinguishes an instruction set.
With PHP, there are two basic instructions for outputting text in a browser: echo and print.
:
PHP variable. Variables are "containers" used to store information
.
Similar to algebra
Xero5
Yizhi6
Z=x+y
In algebra, we use letters (such as x) and assign values to them (such as 5).
From the expression z=x+y above, we can calculate that the value of z is 11.
In PHP, these letters are called variables.
A variable is a container used to store data.
.
PHP variable
Similar to algebra, a PHP variable can be assigned a value (XForm5) or an expression (z=x+y).
Http://www.iis7.com/b/wzjk/
Variables can be short names, such as x and y, or more descriptive names, such as age, carname, totalvolume.
PHP variable rules:
The variable begins with the $symbol, followed by the name of the variable
Variable names must start with a letter or an underscore character
Variable names can only contain alphanumeric characters and underscores (Amurz, 0-9, and _)
Variable names cannot contain spaces
Variable names are case-sensitive ($y and $Y are two different variables)
Both PHP statements and PHP variables are case-sensitive.
.
Create (declare) PHP variable
PHP does not have a command to declare variables.
Variables are created the first time you assign a value to it
Note: when you assign a text value to a variable, put quotation marks around the text value.
.
PHP is a weakly typed language
You do not have to declare the data type of the variable to PHP.
PHP automatically converts the variable to the correct data type based on the value of the variable.
In strongly typed programming languages, we must declare (define) the type and name of a variable before using it.
.
PHP variable scope
The scope of a variable is the part of the script where the variable can be referenced / used.
PHP has four different variable scopes:
Local
Global (global variable)
Static
Parameter
.
Local and global scope
Variables defined outside all functions have a global scope. Global variables can be accessed by any part of the script except functions, and the global keyword is needed to access a global variable in a function.
Variables declared inside the PHP function are local and can only be accessed within the function
You can use the same variable names in different functions because the variable names defined in these functions are local variables and only act within that function.
.
PHP global keyword
The global keyword is used to access global variables within a function.
To call the global variable defined outside the function within the function, we need to add the global keyword to the variable in the function
PHP stores all global variables in an array called $globals [index]. Index saves the name of the variable. This array can be accessed inside the function or can be used directly to update global variables.
.
Static scope
When a function is complete, all its variables are usually deleted. However, sometimes you want a local variable not to be deleted.
To do this, use the static keyword the first time you declare a variable
Then, each time the function is called, the variable will retain the value of the last time the function was called.
Note: this variable is still a local variable of the function.
.
Parameter scope
Parameters are local variables that pass a value to a function by calling code.
Parameters are declared in the parameter list as part of the function declaration
.
1. What is defined outside the function is the global variable, which ranges from the definition to the end of the file.
2. The variable defined in the function is the local variable, and its scope is within the scope of the function definition.
3. The scope between functions does not affect each other.
4. Global keyword or $globals [index] array is required to access global variables within the function.
In php, functions have independent scopes, so local variables will override global variables, even if local variables are not defined as global variables.
To use global variables directly in a function, you can declare them through the global keyword or get them through the custom $GLOBALS array in php.
Thank you for reading! This is the end of this article on "sample Analysis of PHP Grammar and PHP variables". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.