Home > Backend Development > PHP Tutorial > PHP basic learning summary_PHP tutorial

PHP basic learning summary_PHP tutorial

WBOY
Release: 2016-07-21 15:30:40
Original
804 people have browsed it

Lexical structure
1. Case In PHP, keywords, function names, and class names are not case-sensitive, but variable names are case-sensitive.
2. Semicolon, space, newline, braces In PHP, the semicolon indicates the end of a statement. Generally speaking, spaces and line breaks have no real meaning in PHP but can improve the readability of your code. Braces represent a block of statements.
3. Comments PHP supports multiple comment methods. Such as Shell comment method (starting with #), C language comment method (starting with /* and ending with */), C++ language comment method (starting with //). For example: 12345 # Shell annotation mode /* C language annotation mode */ // C++ language annotation mode 4. Direct quantity refers to data values ​​that appear directly in the program, such as data and strings.
5. Identifier, variable name, function name, class name, constant Identifier refers to a name given to variable name, function name and class name. Its first letter is an underscore and uppercase and lowercase letters (ASCII code 0x7F~0xFF is also acceptable, but generally no one uses it.). Other than the first letter, it can be composed of underscores, uppercase and lowercase letters, and numbers 0~9.
Variable names begin with a dollar sign ($), followed by an identifier. ※Variable names are case-sensitive. Function names and class names are directly composed of identifiers. ※Function names and class names are not case-sensitive. PHP constants can be defined with define. Such as 1 define('NAME', 'YUTUO');
6. Keywords The main keywords are as follows $HTTP_COOKIE_VARS $HTTP_ENV_VARS $HTTP_GET_VARS $HTTP_POST_FILES $HTTP_POST_VARS …

PHP learning ( 2) Data types

PHP has 8 data types.
Four basic types: integer, floating point, string, and Boolean;
Two composite types: array and object; two other types: resource and NULL.
1. Integer Integer is an integer and can be positive or negative. The usual range is: -2147483648 ~ 2147483647.
There are three ways to write: decimal, octal and hexadecimal. It can use the function is_int($x) to test whether it is an integer.
For example: 12345678910
$a = 10; //Decimal
$a = -10; //Decimal
$a = 010; //Octal
$a = -010; / /octal
$a = 0x10; //hex
$a = -0x10; //hex
if (is_int($a)) echo $a; …

PHP Learning (3) Variables

As mentioned in the previous article, variables are identifiers prefixed with a dollar sign ($). Such as: $name. Variables can store any type of value; there is no explicit syntax for declaring variables in PHP. The variable is created the first time it is used.
1. Variables of variables Variables of variables, that is, storing a variable name in another variable, such as: 12 $name = 'value'; $$name = '1234'; After execution, a $value will be created Variable, its value is '1234'. 2. Variable reference In PHP, variables are similar to pointers. Variable reference means pointing two variables to the same value. The meaning of alias is similar. Because it points to the same address, changing the value of one variable will also change the other variable. It should be noted that resetting one variable will not change the other variable. This is because resetting the variable only points the variable to NULL without modifying the value pointed by the other variable.
The parameters and return value of the function can be a variable reference, which can prevent copying of large data types (such as strings, arrays, classes).
Sample code:
12345678910111213141516171819 // Change the value of one of the variables
$value_a = 'Test';
$value_b = & $value_a;
$value_b = 'Change';
print "$value_a is $value_a";
print "$value_b is $value_b"; …

PHP Learning (4) Expressions and Operators

An expression in PHP refers to a statement that calculates the result through a certain operator. PHP's operators are basically borrowed from the C language and Perl language.
1. When performing implicit type conversion to digital calculations (addition, subtraction, multiplication, division, remainder, etc.), first convert the string into a number. If the converted number is a floating point number or the expression contains floating point numbers, , then other numbers are converted to floating point numbers for calculation, otherwise integers are used for calculation. When calculating strings (string concatenation), convert the numbers into strings and then concatenate them.
2. Increment and decrement Increment and decrement can be placed before or after the variable. Putting it before the variable means adding (subtracting) 1 first and then calculating. Putting it after the variable means calculating first and then adding (subtracting) 1
3. Type conversion The type conversion operator has some synonymous operators. For example: (int) and (integer), (float) and (real), (bool) and (boolean) Attachment: The following table lists the PHP operators, in which the "priority" is from large to small (bigger priority "high" indicates the priority of the operator; "associativity" indicates whether the operator is left associative or right associative ("none" indicates no associativity).
Priority Associativity Operator Description 19 No new creates object 18 Right [] Array subscript 17 Right! ,~ Logical negation, bitwise negation right++, – Increment, decrement right (int), (double), (string), (array), (object) type conversion right...

PHP learning (5) Flow control statements

In PHP, flow control statements mainly consist of conditional statements and loop statements. Among them, flow control statements include if/else and switch statements; loop statements include while and for statements.
1. IF statement In PHP, the IF statement has two grammatical structures.One uses braces to represent statement blocks, and the other uses colons to represent statement blocks. The former is generally used in pure code, and the latter is generally used when code is combined with HTML. The two writing methods are as follows: 1234567891011121314151617 // Braces represent the statement block if ($value) { // Operation; } elseif($value) { // Operation; } else { // Operation; } // Colon represents the statement block if ( $value) : // Operation; elseif($value) : // Operation; else : // Operation; endif; …

PHP Learning (6) Contains code and embedded PHP

Including code in PHP, including code has four functions, include include_once require require_once.
The main difference between include and require is that the require function will throw a fatal error if the file does not exist, while include will only throw a warning.
include include_once and require require_once, where the suffix once means that if the code already includes the file, the file will not be referenced again. Embedding PHP There are four ways to embed PHP in HTML: XML form, SGML form, ASP form, and script form. The ASP form is not supported by default. You must modify asp_tags to On in the PHP configuration file [PHP.ini].
The sample codes for the four methods are as follows: 123456789101112 // XML format
echo 'Hello, world';
?>
// SGML format
< ?
echo 'Hello, world';
?> // ASP format
<%
echo 'Hello, world';
%>
// Script format

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template