23:
3. Notes
3.1 single line comment: // or # multi-line comment:/* Description */
More than 3.2 line comments cannot be nested, but can contain single line comments; single line comments can also contain multiple lines of comments. Just like this
1: <?php
2: // echo "test";/* a single line contains multiple line annotators */
3:/* echo 'test'; // contains a single-line annotator */
4: ?>
Iii. Variables
1. Use of Variables
1: <?php
2: $ a = 1; // declare a variable
3: $ B = "php"; // declare a variable B
4: $ 8d = 2; // invalid variable name. It can only start with a letter or underline and does not contain spaces
5:
6: $ I site is = "php"; // valid variable name, which can be in Chinese
7: /*
8: * The following three function call methods are equivalent.
9: * keywords and built-in functions and user-defined class names. The function names are case-insensitive.
10: */
11: phpinfo();
12: PhpInfo();
13: PHPINFO();
14:
15:
16: /*
17: * The following three variables are different.
18: * variable names are case sensitive
19: */
20: $name = "php1";
21: $Name = "php2";
22: $NAME = "php3";
23:
24: // variable: variable names can be dynamically set
25: $hi = "hello";
26: $$hi = "world";
27: // hello world is output below
28: echo "$hi $hello";
29: echo "$hi ${$hi}";
30:
31: // variable assignment
32: $ foo = "B" // value assignment
33: $ bar = & $ foo // reference value assignment
34: $bar = "LZ";
35: echo "$ foo"; // output LZ
36: $ cde = $ foo; // value assignment
37: $cde = "E";
38: echo "$ foo"; // output LZ
39: ?>
2. Variable type
Iv. Constants
1. Define and use
1: <?php
2: /*
3: *boolean define(string name,mixed value[,bool case_insensitive)
4: * name: constant name; value: constant value; the third value is an optional Boolean value. The default value is FALSE (Case Insensitive)
5: */
6: define("FLO",1000);
7: echo FLO; // output 1000
8:
9: // use the define function to check whether a FLO constant exists. If yes, the constant value is output.
10: if(define("FLO"))
11: {
12: echo FLO;
13: }
14: ?>
2. constants and variables
2.1 The scope of a constant is global. You can declare and access a constant anywhere in the script.
2.2 There is no $ before a constant, and a constant cannot be defined using a value assignment statement.
2.3 Once a constant is defined, it cannot be redefined or canceled until the script stops running.
2.4 The constant value can only be a scalar (a type in boolean, integer, float, string)
3. predefined constants of the system
4. Common magic Constants
Source: http://www.ido321.com/510.html
Basic php syntax
Double quotation marks are used to output strings. Example: echo "data insertion failed, error message: <br> ";
And "insert into testtable VALUES ('". $ xm. "',". $ nl. ")"; in insert into testtable VALUES is a string, which means to INSERT to the database, two "" are a group, put. $ xm. separated ,(. $ xm .) $ xm is a variable. echo is used when a variable is displayed in php.
Basic php syntax
An equal sign is a value from right to left.
The two equal signs are equal.
The three equal signs are absolutely equal (the values and data types are completely equal)
To avoid the problem in the third line, we recommend that you write the conditional statement ("" = $ I), so that an error is returned even if the equal sign is missing, rather than executing the assignment.