Home >Backend Development >PHP Tutorial >A good PHP basic study note_PHP tutorial
1. Four representation forms of PHP fragments.
Standard tags:
short tags: ?> You need to set short _open_tag=on in php.ini, the default is on >Need to set asp_tags=on in php.ini, the default is off
script tags:
2. PHP variables and data types
1) $variable, variables start with letters, _, and cannot have spaces
2) Assignment $variable=value;
3) Weak type, direct assignment, no need to display the declared data type
4) Basic data Type: Integer, Double, String, Boolean, Object (object or class), Array (array)
5) Special data types: Resource (reference to third-party resources (such as database)), Null (empty, uninitialized) Variables)
3. Operators
1) Assignment operators: =
2) Arithmetic operators: +, -, *, /, % (modulo)
3) Connection operators :., no matter what the operand is, it will be treated as String, and the result will be returned String
4) Combined Assignment Operators total assignment operators: +=, *=, /=, -=, %=, .=
5 ) Automatically Incrementing and Decrementing automatic increase and decrease operators:
(1)$variable+=1 <=>$variable++;$variable-=1 <=>$variable-, just like c language, do it first For other operations, follow ++ or -
(2) ++$variable, -$variable, first ++ or -, and then do other operations
6) Comparison operator: = = (left side is equal to right side), != (the left side is not equal to the right side), = = (the left side is equal to the right side, and the data type is the same), >=, >, <, <=
7) Logical operators: || ó or, &&óand , xor (when one and only one of the left and right sides is true, return true),!
4. Comments:
Single-line comments: //, #
Multi-line comments: /* */
5 , Each statement ends with ;, the same as java
6. Define constants: define("CONSTANS_NAME",value)
7. Print statement: print, the same as c language
8. Process control statement
1) If statement:
(1) if(expression)
{
//code to excute if expression evaluates to true
}
(2) if(expression)
{
}
else
{
}
(3)if(expression1)
{
}
elseif(expression2)
{
}
else
{
}
2) swich statement
switch (expression)
{
case result
// execute this if expression results in result1
break;
case result
// execute this if expression results in result2
break;
default:
// execute this if no break statement
// has been encountered hitherto
}
3) ? Operator:
(expression)?returned_if_expression_is_true:returned_if_expression_is_false;
4) while statement:
(1) while (expression)
{
// do something
}
(2) do
{
// code to be executed
} while (expression);
5) for statement:
for (initialization expression; test expression; modification expression) {
// code to be executed
}
6) break; continue
9. Write function
1) Define function:
function function_name($argument1,$argument2,……) //Formal parameters
{
//function code here;
}
2) Function call
function_name($argument1,$argument2,……); //Formal parameters
3) Dynamic Function Calls:
");
numberedHeading("Doodads"); /*When called for the first time, print $num_of_calls value is 2, because the variable is static type, static type is resident in memory*/
print("Finest in the world
?>
6) Passing value (value) and passing reference (reference):
Passing value: function function_name($argument)