The basic syntax of PHP

PHP (Hypertext Preprocessor, hypertext preprocessor).

    Under Windows configuration PHP Address: http: //www.microsoft.com/web/webmatrix/

A command delimiter "semicolon"
         

Semantic divided into two types: one is used in the program structure definition statements, such as process control, function definitions, class definitions, statements used to define the structure of the program used. It can not be used after the end of the structure as a semicolon statement;

        Another function is used in the program executing the statement, for example, variable declaration, output, etc. of the function call, the statement is used to perform certain functions in the program, the instruction statement can also be, php need end with a semicolon after each instruction.

2 Program Notes 

Three forms php comments:

To "/ *" and "* /" closed multi-line comment character,
"//" and "#" start a single line comment character
3 is a blank in the program processing
 

The following conditions should always use two blank lines:

Between two code segments of a source file.
Statement between two classes.
The following conditions should always use a blank line:
Between two function declarations.
Between the first statement of local variables and function within the function.
Block comments or single-line comments.
Between two code segments within a logic function to improve readability.
  Space rules apply:
Generally used between the keyword and the parentheses, between the function name and the opening parenthesis should not use spaces.
Add a space after the comma general function parameter list in.
You should add a space (binary yuan yuan operator, except with the hospital operator) between mathematical formula operands and operators.
for statement should be separated by a comma expression, add a space behind. 

Second, variable

First assignment, we create variables. Must use the "$" followed by the variable name represents. Again to the variable before the variable assignment overrides. 

After php variable declaration has a certain range, the range of variables that is defined in the context of its background (that is, it entered into force range). Most, if not php variables declared inside a function, within only a statement at the end of the file using a separate range. This single scope spans not only the ?> Tag at the end of use, can be used in all PHP mode on a page, but also contains the files include and require introduction. If you are using SESSION COOKIE or can also be applied to multiple pages.

   In the period of use of a variable, we can use the unset () function to release the specified variable, using isset () function and use detection variable is set empty () function detects a face is empty.
empty () and isset () the difference:
    If empty () value of the parameter is non-null or non-zero function, the empty () returns false. "", 0, "0", null, false, array (), var $ var, and no properties of the object will be considered empty. If the argument is empty, it returns true.
     If the function isset () parameter is present, it returns true. When using isset () is arranged to detect a null or variable unset () a variable release, will return false.
     Note: The byte NULL ( ) is not equal to null constant.
    Recommendation: Use the presence of empty ($ var) whether the variable and can not be empty!.
1 variable naming
 

Variable names are case-sensitive. But the class name and function name and the built structure and user-defined keywords are case-insensitive.


Hump ​​nomenclature. Such as: $ aaaBBBccc.

2 variable variable 

The variable a variable value may be used as a common variable variable variable variable name.

3 reference to a variable assignment 

  Variables are always assigned by value. That is, when the value of an expression to a variable, the entire value of the original expression is copied into the destination variable. Wherein changing the value of a variable, the variable will not affect the other.

  Assignment by reference, the "&" before added to the variable. Copy the reference variable to a new variable, a common reference point, any change in the value of a variable, it will affect the other. Only the names of the variables can only be assigned by reference. Two variable references will not be assigned the same body in memory, but the respective values associated with them, based on this, unset () will not lead to the disappearance of another variable.

 

Type 4 variables 
4 kinds of scalar types: boolean (Boolean), integer (integer), float (float), string (string)
Two kinds of complex type: array (array), object (object)
Two kinds of special types: resource (resources), NULL 
If you want to see the value and type of an expression, you can use the function var_dump (). 
Boolean
The following values ​​are considered false
1) A Boolean value false .
2) integer value 0 (zero) is false, -1, and other non-zero (whether positive or negative) as is considered true.
3) floating-point value 0.0 (zero).
4) empty string, and the string "0"
5) no member variables of an array.
6) special type NULL 
Integer
        Maximum range 2,147,483,647. PHP does not support unsigned integer, if a given number exceeds the maximum range, it will be interpreted as a float. 
Float
  Never compare two floating-point numbers for equality.
  If you need higher precision, you should use the arbitrary precision math functions or gmp () function. 
String
Single-quoted string:
        If you want to reference a single quote in single quotation marks, you need to use a backslash () escaped.
        Or if the end of the string needs to occur before a single backslash quotes, it requires represented by two backslash.
        Where the variables appear not substitute the variable's value. That does not resolve single quotes php variable, but the variable name is output. Defining a simple string, a higher efficiency of single-quoted strings. 

Double-quoted strings: wherein the variables are resolved.


 

Delimiter string:
        Use <<< start delimiter, after providing an identifier, then the string is included, the top grid and finally writing the same identifier.
      Outside the delimiter text processing can not initialize class members, and the performance of the double-quoted string on the same, but without the double quotes. This means that no escape quotes in the text delimiters, but can still be used to escape the symbol in double quotes listed above can be used. Further delimiter variables will be resolved, but when expressing complex variables and the text string as the delimiter also be noted. So long definition string delimiter can be easily used, it is typically used to interrupt the output from the text file or database.
Array (Array)
Use print_r () function to see the entire contents of the array.
Object (Object)
->: is a reference to the object properties, methods
 
Resource Type (Resource)
  NULL type
        The special NULL value represents a variable has no value, NULL type only possible value is NULL. NULL does not mean that space does not mean zero, nor is it an empty string, but represents a variable is empty. NULL is not case sensitive, in the following cases a variable is considered to be NULL.
a) the variable direct assignment to NULL.
Variable b) declaration has not yet been assigned.
c) The unset () function variables destruction.
  Pseudo-Types
mixed: Description parameter can take a variety of different (but not necessarily all) types. E.g. getype () can accept all types php, str_replace () can accept strings and arrays.
number: indicates that a parameter can be either integer or float.
callback: Some such call_user_function () or usort () function accepts a user-defined function as a parameter. The callback function can not only be a simple function, he can also be a subject of methods, including static class methods. Php with a function to transfer the function name string. The transfer function can be any built-in or user-defined, except that array (), echo (), empty (), eval (), exit (), isset (), list (), print () and unset ().
Conversion between data types

        Automatic transition typically occurs when different types of data variable mixing operation, if the amount of calculation participate in different types of element, is converted into the substantially the same type, and performing the calculation. Usually only four scalar types (integer, float, string, boolean) before using an automatic type conversion. How the operands myopia that does not change the type of the operation to the book itself, the change is evaluated. While oil automatic type conversion is done automatically, but the mixing operation, to follow automatically converted data converted by the increased length direction, to ensure the accuracy is not lowered.

There are involved in computing Boolean value, true will be converted to integer 1, flase 0 after converting to integer arithmetic participation.

    When involved in computing NULL value, NULL value into an integer 0 during operation.
    When participation type integer and a float operation, first converted to integer variables during operation after float.
    And a numeric character string (integer, float) data involved in computing, converted to a digital string, operation involved. The converted digital value from a string is started, if the numeric string string starting with no decimal point to integer numeric type. If a decimal point number is converted to float.
 
Cast
    Together with certain types of brackets can be used before the variable specific conversion function to convert again, i.e. intval (), floatval (), strval () or with setType () function converts type.
    intval()floatval()strval()强制类型转换没有改变变量本身的类型,而是通过转换将得到的新类型的数据赋值给新的变量,原变量的类型和值不变。如果需要改变自身的类型与值,可以使用setType()函数来设置变量的类型。
变量类型的测试函数
is_bool():判断是否是布尔型。
is_int()、is_integer()和is_long():判断是否是整型。
is_float()、is_double()和is_real():判断是否是浮点数。
is_string():判断是否是字符串。
is_array():判断是否是数组。
is_object():判断是否是对象。
is_resource():判断是否是资源类型。
is_null():判断是否为空。
is_scalar():判断是否是标量,也就是一个整数、浮点数、布尔型或字符串。
is_numberic():判断是否是任何类型的数字或数字字符串。
is_callable():判断是否是有效的函数名。

三、常量

常量只能包含四种标量数据。

常量的定义

  1.   define(string namemixed value[,bool case_insensitive]);
第一个参数为常量名,第二个参数为常量的值或表达式,第三个参数是可选的,如果把case_insensitive设为true,则常数将会定义成不区分大小写。如果只想检测是否定义了某常量,用defined()函数。

 预定义常量


循环语句

    break

    在循环语句中中断循环语句,也就是结束循环语句的执行。
    break语句可以将深埋在嵌套循环中的语句退出指定层数或直接退出最外层,break是接受一个可选的数字参数来决定跳出几重语句。break可以跳出几重循环语句或是几重switch语句。
 continue
    continue 语句只能使用在循环语句内部,功能是跳过该次循环,继续执行下一次循环结构。在while和do-while语句中continue语句跳转到循环条件处开始继续执行,对于for循环随后的动作是变量更新。.
   接受一个可选数字参数来决定条出多重语句。
   在循环中遇到continue语句后,就不会执行该循环中位于是continue后的任何语句。
   continue语句用于结束循环,继续下一次循环。
 exit
   当前脚本只要执行到exit语句,而不管它在那个结构中都会直接退出当前脚本。exit()是一个函数,die()函数就是exit()函数的别名,可以带有一个参数输出一条信息,并退出当前脚本.
函数

Guess you like

Origin www.cnblogs.com/it1000/p/11088156.html