PHP Learning Summary 1,
Echo "welcome to imooc! "; Output string
?>
2. the string is enclosed by "" or ''. The two characters can be connected.
3. comment
//
4. line feed
5. the variable name must be identified by the $ symbol
6. The "var_dump" function can display the data type of our variables.
Var_dump ($ var_name );
Var_dump ($ n );
7. variable names in PHP are case sensitive.
8. array definition
$ Var_array = array ("123 ");
9. you do not have to declare the data type of a variable to PHP. PHP automatically converts the variable to an automatic data type.
10, scalar type-boolean type boolean
Case insensitive
11,
Scalar type-integer
Integer: similar to common integers. It can be specified in decimal, octal, and hexadecimal notation. Decimal is the number used in daily use. in octal notation, "0" must be added before the number (this 0 is an Arabic digit 0, not an English letter "ou"); hexadecimal format, "0x" must be added before the number (this 0 is also an Arabic digit 0, not "euro ). For example:
12. scalar type-floating point type
Float (floating-point number, double-precision number, or real number), that is, decimals, can be expressed by decimal points or scientific notation. Scientific notation can use lower-case e or upper-case E. For example:
13.
Scalar type-string (2)
Solution 1: embed double quotation marks in single quotes and embed them directly
Solution 2: embed single quotes in double quotes and embed them directly
Solution 3: Use the escape character "\",
$ Str_string3 = 'question A: \ 'can you tell me the URL? \'';
14,
When double quotation marks contain variables, the variables are connected with the content in double quotation marks;
When a single quotation mark contains a variable, the variable is output as a string.
15,
What should I do if my string is long?
< I have a donkey, and I never ride it.
One day I was riding on to the market.
I am proud to have a small whip in my hand.
I don't know why. I fell into the mud.
GOD;
The end of a line must start with another line. in addition to "GOD" and end with ";", this line cannot contain any other character,
16. resources
Resources are built and used by specialized functions, such as opening files, data connections, and drawing canvases.
A. read file resources
$ File_handle = fopen ("/data/webroot/resource/php/f.txt", "r ");
If ($ file_handle ){
// Use the while loop (the loop structure in the subsequent language structure statements will be described in detail) to read the file row by row, and then output the text of each row
While (! Feof ($ file_handle) {// determines whether the last row is reached
$ Line = fgets ($ file_handle); // read a line of text
Echo $ line; // output a line of text
Echo"
"; // Line feed
}
}
Fclose ($ file_handle); // Close File Resources
20,
The second special type-null type,
NULL (NULL): NULL is a NULL type and is case insensitive. The NULL type has only one value, indicating that a variable has no value. if it is assigned NULL or has not been assigned a value, or unset (). in these three cases, the variable is considered NULL.
Case insensitive
Eg. $ var3 = "happy holidays! ";
Unset ($ var3 );
21. constant
The syntax format of the define () function is:
bool define(string $constant_name, mixed $value[, $case_sensitive = true])
The first parameter "constant_name" is a required parameter. it is a constant name, that is, a flag. the naming rule of a constant is the same as that of a variable. Note that it does not contain the dollar symbol. The second parameter "value" is a required parameter, which is the value of a constant. The third parameter "case_sensitive" is an optional parameter, which specifies whether it is case sensitive. if it is set to true, it indicates no sensitivity. generally, if the third parameter is not specified, the default value of the third parameter is false.
$ P = "PII ";
Define ("PI", 3.14 );
Define ($ p, 3.14 );
22,
System constant
(1) _ FILE _: php program FILE name. It helps us to obtain the physical location of the current file on the server.
(2) _ LINE _: Number of PHP program files. It tells us the number of lines in the current code.
(3) PHP_VERSION: version number of the current parser. It tells us the version number of the current PHP parser. we can know in advance whether our PHP code can be parsed by the PHP parser.
(4) PHP_ OS: name of the operating system for executing the current PHP version. It tells us the name of the operating system used by the server, and we can optimize our code based on the operating system.
23. how to set the value of A to A constant?
B. use the constant function
mixed constant(string constant_name)
Eg. $ area = constant ($ p) * $ r;
24,
How to determine whether a constant is defined
The defined () function helps us determine whether a constant has been defined. Its syntax format is:
bool defined(string constants_name)
Only the constant_name parameter indicates the name of the constant to be obtained. If yes, true is returned; otherwise, false is returned. (Note: bool indicates that the return type of the function is Boolean)
25. value assignment operator
(1) "=": assigns the value of the right expression to the number of operations on the left. It copies the expression value on the right to the number of operations on the left. In other words, I first applied a piece of memory for the number of operations on the left, and then put the copied value in the memory.
(2) "&": reference value assignment, meaning that both variables point to the same data. It will make the two variables share a piece of memory. if the data stored in this memory changes, the values of the two variables will change.
26,
Comparison Operators
Eg $ a = 1;
$ B = "1"; $ a = $ B but $! ==$ B
27.
Ternary operators ("? : ") The ternary operator is also a comparison operator. for an expression (expr1 )? (Expr2) :( expr3). If the value of expr1 is true, the value of this expression is expr2; otherwise, it is expr3.
28. logical operators
29.
String concatenation operator
(1) concatenation operator ("."): it returns the string obtained after attaching the right parameter to the left parameter.
(2) join value assignment operator (". ="): It attaches the parameter on the right to the parameter on the left, and gives the connected value to the parameter on the left.
30.
Error Control Operator
Before placing @ in a PHP expression, any error information generated by the expression may be ignored, and any error information generated by the expression will be stored in the variable $ php_errormsg.
Eg. $ conn = @ mysql_connect ("localhost", "username", "password ");
Echo "error, error cause:". $ php_errormsg;
31,
Foreach loop statement
(1) only values, not subscript
(2) obtain both the subscript and value.
Value) {// the task to be executed}?>
Eg. $ students = array (
'20180101' => 'Line-Hu chong ',
'20140901' => 'Lin pingzhi ',
'20140901' => 'quyang ',
'20140901' => 'Ren Yingying ',
'20140901' => 'Ask days ',
'000000' => 'let's reach ',
'20140901' => 'dashboard ',
'000000' => '正 ',
'20140901' => 'yuebu group ',
'20140901' => 'chinance ',
); // The student ID and name of 10 students, which are stored in arrays
// Use the loop structure to traverse the array and obtain the student ID and name
Foreach ($ students as $ num => $ v)
{
Echo $ num;
Echo $ v; // output (print) name
Echo"
";
}
32. array
One-dimensional array
$ Students = array (
'20180101' => 'Line-Hu chong ',
'20140901' => 'Lin pingzhi ',
'20140901' => 'quyang ',
'20140901' => 'Ren Yingying ',
'20140901' => 'Ask days ',
'000000' => 'let's reach ',
'20140901' => 'dashboard ',
'000000' => '正 ',
'20140901' => 'yuebu group ',
'20140901' => 'chinance ',
);
Two-dimensional array
$ Students = array (
'20140901' => array ('line-Line-line-based boundary, "59 "),
'20140901' => array ('Lin pingzhi', "44 "),
'20140901' => array ('quyang', "89 "),
'20140901' => array ('Ren Yingying ', "92 "),
'20140901' => array ('Ask days', "93 "),
'20140901' => array ('Let's go ', "87 "),
'20140901' => array ('dashboard ', "58 "),
'20140901' => array ('founder ', "74 "),
'20140901' => array ('yueda group', "91 "),
'20140901' => array ('chinance', "90 "),
); // The student ID, name, and score of 10 students, which are stored in arrays.
Values from a two-dimensional array:
Foreach ($ students as $ key => $ val)
{// Use the cyclic structure to traverse the array and obtain the student ID
Echo $ key; // output student ID
Echo ":";
// Name and score of cyclic output
Foreach ($ val as $ v)
{
Echo $ v;
}
Echo"
";
}