Variable
Defining a variable is the memory request space to the server to store the data.
Such as:
$var _name = "Apple";
“ = "On the left is Variable name , right is Variable Value , after you have finished defining the variables, you need one ; tell the server that this line of instructions is over. Where the variable name must be identified by the $ symbol;
Variable naming rules
1. Variable names must begin with a letter or underscore "_", such as "$_name", "$name", "$name 2", etc., but "$9name" is not correct.
2, the variable name can only be composed of letters, numbers, and "_", but also contain Chinese characters. such as "$_qq", "$QQ 308", "$my _apple", "such as" $name I Wait ", but" $name * "is wrong.
3. Variable names are not allowed to contain spaces. When the variable name consists of multiple words, it is recommended to use "_" to separate (for example $my _apple), commonly known as the underscore method, or start with a capital letter such as $myApple, commonly known as camel-named (also known as the Hump name).
In particular, it is important to note that in PHP variable names are case-sensitive, such as "$my _book" and "$my _book" represent two different variables.
Boolean type
Boolean Type (Boolean): There are only two values, one is true and the other is false, which can be understood as yes or No. It is not case-sensitive, which means that the "true" and "true" effects are the same.
Integral type
Integral type (integer): Similar to a common integer. It can be specified in decimal, octal, hexadecimal. Decimal is the daily use of numbers, octal, the number must be added "0" (this 0 is the Arabic numeral 0, not the English letter "ou" oh); hexadecimal, the number must be preceded by "0x".
Floating point Type
Floating-point (floating-point, double-precision, or real-number), which is usually said to be decimals, can be represented by a decimal point or by scientific notation. Scientific notation can be used in lowercase e, or in uppercase E
String
Strings are composed of a series of characters, in php, characters and bytes, that is, a total of 256 different characters of the possibility.
1.
The string type can be defined in three ways: single-quote, double-quote, and Heredoc-structured.
2.
when you include quotes in your string, :
First scenario: Double quotation marks are embedded in single quotation marks, as shown in line 2nd;
The second scenario: enclose the single quotation mark in double quotation marks, as shown in line 3rd;
Third scenario: Using the escape character "\"
3. When a variable is enclosed in double quotes, the variable is concatenated with the contents of the double quotation mark;
When a variable is included in a single quotation mark, the variable is exported as a string.
Special types-Resources
Resources (Resource): resources are created and used by specialized functions, such as open files, data connections, and graphical canvases. We can manipulate resources (create, use, and release). Any resources should be released in a timely manner when they are not needed. If we forget to release the resources, the system automatically enables the garbage collection mechanism to reclaim the resources after the page has been executed to avoid the memory being exhausted.
Examples are as follows:
Special type-NULL type
Null (NULL): null is a null type, is not case sensitive, the null type has only one value, indicating that a variable has no value, when it is assigned to NULL, or has not yet been assigned, or is unset (), the variables are considered NULL in three cases.
Constant
Constants in PHP are divided into custom constants and system constants.
1. A custom constant is a constant defined according to the needs of our development, and it is defined by using the function define () in PHP.
The syntax format for the define () function is:
BOOL Define (String $constant _name, mixed $value, [$case _sensitive = True])
It has 3 parameters:
The first parameter, "Constant_name", is a required parameter, a constant name, or a marker, and the name of the constant is consistent with the variable, but be aware that it does not have a dollar sign. The second parameter, "value," is a required parameter, which is the value of the constant. The third parameter, "Case_sensitive", is an optional parameter, specifying whether it is case sensitive, set to true to be insensitive, and generally without specifying a third parameter, the value of the default third parameter is False.
2. System constants are constants that PHP has already defined, and we can use them directly, and common system constants are:
(1) __file__:p hp program file name. It can help us get the current file in the physical location of the server.
(2) __line__:P HP program file line number. It can tell us the current code in the first few lines.
(3) Php_version: The version number of the current parser. It can tell us the current PHP parser version number, we can know in advance whether our PHP code can be parsed by the PHP parser.
(4) Php_os: Executes the current PHP version of the operating system name. It can tell us the name of the operating system used by the server, and we can optimize our code based on the operating system.
3.
There are two ways to take a value for a constant value. The first is to get the value directly using the constant name;
The second is the use of the constant () function.
4.
The defined () function helps us to determine whether a constant has been defined and its syntax is:
bool Defined (string constants_name)
It only has the parameter constant_name, refers to gets the name of the constant, returns the Boolean type True if present, otherwise returns the Boolean type false;
Operator
1.
PHP operators are generally divided into arithmetic operators, assignment operators, comparison operators, ternary operators, logical operators, string join operators, error control operators.
Arithmetic operators are primarily used for arithmetic operations, such as addition, subtraction, multiplication, and division. The usual arithmetic operators in PHP correspond to the following table:
2.
There are two types of assignment operators for HP, namely:
(1) "=": assigns the value of the right expression to the left operand. It copies the value of the right expression to the left-hand operand. In other words, the left operand is first requested for a piece of memory, and then the copied value is placed in this memory.
(2) "&": Reference assignment means that both variables point to the same data. It will allow two variables to share a piece of memory, and if the memory stored data changes, then the values of the two variables will change.
3.
Comparison operators are mainly used for comparison operations, such as: equals, congruent, unequal, greater than, less than. The comparison operators commonly used in PHP are the following table:
4.
("?:") The ternary operator is also a comparison operator, for expressions (EXPR1)? (EXPR2):(EXPR3), if the value of EXPR1 is true, the value of this expression is expr2, otherwise EXPR3.
logical operators
Logical operators are used for logical operations such as logic and logic, logical XOR, logical negation, and logical operators commonly used in PHP as follows: (click to view larger image)
Where or, xor than &&, | | The priority level is low.
String Join operators
The string join operator is to concatenate two strings, and the string join operators provided in PHP are:
(1) Join operator (".") : It returns the string that is appended to the right argument after the left argument.
(2) Connection assignment operator (". ="): It attaches the right argument to the left argument.
Error control operators in PHP
An error control operator "@" is provided in PHP, and we do not want an error message to be displayed to the customer when there are some expressions that may be wrong during the run, which is unfriendly to the user. Therefore, you can put the @ before a PHP expression, any error message that the expression may produce is ignored;
If the Track_error (which is set in php.ini) is activated, any error message generated by the expression is stored in the variable $php_errormsg, which is overwritten every time an error occurs, so you must check it as early as possible if you want to use it.
It is important to note that the error control prefix "@" does not mask the parsing of the error information, it cannot be placed before the definition of a function or class, nor can it be used for conditional structures such as if and foreach.
Note:ceil usage: double ceil(double x); function: Returns the smallest integer header file that is greater than or equal to the specified expression
If...else ...
if (condition) {//Assign server Dry task a}else{//Assign server to dry task B}
Note: Date_default_timezone_set (' Asia/shanghai '); Set the default time zone.
Date (Format,timestamp)
Switch...case ...
The "Switch...case ..." syntax in PHP is as follows:
The while loop statement is as follows:
Note: $num = rand (1,20);//random number
The Do...while Loop statement syntax is as follows:
The FOR Loop statement structure is as follows:
The Foreach Loop statement for the loop structure in PHP
In PHP, the Foreach Loop statement, commonly used to iterate over an array, is generally used in two ways: Do not remove the label, remove the label.
(1) value only, do not remove the label
(2) Remove the mark and value at the same time
Value) {//Perform the task}?>
The above describes the Imoocphp Learning notes (introductory), including aspects of the content, I hope to be interested in PHP tutorial friends helpful.