Recently there is a H5 project needs, the need for service side, after the investigation decided to use PHP to implement an HTTP server, so began to review PHP syntax, by the way to record the key points, so that you can revisit at any time. The contents of the PHP manual are compiled from W3school.
What is PHP?
PHP is the acronym for "PHP Hypertext Preprocessor"
The PHP code executes on the server, and the result is returned in plain text to the browser
PHP files can contain text, HTML, CSS, and PHP code
The suffix of the PHP file is ". php"
The PHP script can be placed anywhere in the document.
PHP files usually contain HTML tags and some php script code.
PHP Basic Syntax
Script with End
Statement ends with a semicolon (;).
The closing tag of a code block also automatically indicates a semicolon (so you don't have to use a semicolon in the last line of the PHP code block).
Or # indicates a single line comment
/**/is a multiline comment
Variable case Sensitivity
user-defined functions, classes, and keywords are insensitive to case sensitivity (for example, if, else, Echo, and so on).
PHP variables
Variable weak type
The variable begins with a $ symbol followed by the name of the variable, such as $x = 5;
Variables declared outside the function have Global scope and can only be accessed outside of the function.
Variables declared inside a function have a local scope and can only be accessed inside the function.
The global keyword is used to access variables within the function. To do this, use the Global keyword before (inside the function) variable:
Example 1:
Example 2:
PHP Static Keywords
PHP Static Keywords
Typically, all variables are deleted when the function finishes/executes. However, sometimes I need to not delete a local variable. Achieving this requires a bit of further work.
To do this, use the static keyword when you first declare a variable:
Then, whenever the function is called, the information stored by the variable is the information contained in the last Call of the function.
Note: The variable is still a local variable of the function.