PHP Learning Note I. Basic knowledge
One, PHP four type of writing
1. XML markup Style:
2, short mark (need to modify in PHP config file):
3, ASP style (need to modify in PHP configuration file):<%...%>
4. Script Style:
Second, PHP comments
1, C + + style single-line comment: "//".
2, Shell-style single-line comment: "#".
3, C-style multi-line Comment: "/* * * *".
Third, PHP variables
1, PHP does not require re-use before the declaration of variables, the first time you assign a variable, you create a variable.
2, the Declaration of variables in PHP must start with "$", followed by the variable name.
3. The variable name consists of a letter, a number, an underscore, but cannot begin with a number. Variable names are case-sensitive.
4. Variable names must be meaningful.
5, variable variable.
6. The scope of the variable is local (the variable outside the method cannot be used within the method, and the variable within the method cannot be used outside the method).
7, the scope of the constant is global (can be used throughout the script, using the Define function to define constants).
6. Reference Assignment
Iv. Types of PHP data
Var_dump (variable name): View the type of the variable. such as: $a=100 var_dump($a); 输出:int .
1. Basic Data Type
Integer (integer), floating-point (float or double), Boolean (Boolean), String.
PHP does not strictly specify the maximum length of a string.
You can use single and double quotation marks and qualifiers (typically used for multiline characters) to define a string.
The difference between single and double quotation marks: double quotes support parsing variable names, and parsing escape characters. Single quotation marks are not supported.
When there is no above requirement, try to use single quotation marks to define the string. Because single-quote execution is efficient.
2. Composite data Type
2.1. Arrays (Array)
2.2. Objects (object)
3. Special Data Types
3.1, null: Indicates that a variable has a null value and is not case-sensitive.
The variable is considered null in the following cases;
(1), assign the variable directly to NULL.$a=null;
(2), the declared variable has not been assigned a value.var_dump($a);
(3), the variable that is destroyed by the unset function.$a=100 unset($a); var_dump($a);
3.2. Resource Type (Resource)
A resource is a special type of variable that holds a reference to an external resource. Resources are created and used through specialized functions.
V. Conversion of data types
The string is converted to an integer type. The contents of the first non-digit number from left to right are all dropped.
$a='100php100'; $b=(int)$a; var_dump($b); 输出:int 100
Automatic conversion
VI, constants
1, the scope of the constant is global, can be declared and accessible anywhere in the script.
2. Constants contain only Boolean, Integer, floating-point, and string types.
3, in accordance with the Convention, constant identifiers are always thanked; there is no "$" symbol before the constant.
Custom Constants
System constants
";//换行echo __LINE__;//当前语句所在行号echo "
";echo PHP_VERSION;//php版本号echo "
";echo PHP_OS;//当前windows操作系统?>