Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The basis of PHP grammar and sample analysis of variables

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the basis of PHP grammar and sample analysis of variables, the article is very detailed, has a certain reference value, interested friends must read it!

What is PHP?

PHP is the acronym of "PHP Hypertext Preprocessor"

The PHP code executes on the server and the result is returned to the browser in plain text

PHP files can contain text, HTML, CSS, and PHP code

The suffix of the PHP file is ".php"

PHP scripts can be placed anywhere in the document.

PHP files usually contain HTML tags and some PHP script code.

Basic syntax of PHP

The script ends with

The statement ends with a semicolon

The closing tag of the code block also automatically indicates the semicolon (so you don't have to use a semicolon on the last line of the PHP code block).

/ / or # indicates a single-line comment

/ * / is a multiline comment

Variables are case sensitive

User-defined functions, classes, and keywords are case-insensitive (such as if, else, echo, etc.)

PHP constant

Once a constant is defined, it cannot be changed or undefined.

Constants are automatically global throughout the script.

The constant is set using the define () function, which takes three parameters:

The first parameter defines the constant name

The second parameter defines a constant value

(optional) the third parameter specifies whether the constant name is case-sensitive. The default is false.

Valid constant names are opened with characters or underscores

PHP variable

Variable weak type

The variable begins with the $sign, followed by the name of the variable, such as $xroom5

Variables declared outside the function have Global scope and can only be accessed outside the function.

Variables declared inside the function have LOCAL scope and can only be accessed within the function.

The global keyword is used to access global variables within a function. To do this, use the global keyword before the variable (inside the function):

Example 1:

Example 2:

PHP Static keyword

Typically, when the function completes / executes, all variables are deleted. However, sometimes I need not to delete a local variable. Further work is needed to achieve this.

To do this, use the static keyword when you first declare a variable:

Then, every time a function is called, the information stored in this variable is the information contained in the last time the function was called.

Note: this variable is still a local variable of the function.

The above is all the content of this article "the Foundation of PHP Grammar and sample Analysis of variables". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report