This article mainly introduces the PHP definition string of four ways, has a certain reference value, now share to everyone, the need for friends can refer to
1. Single quotation mark
In single quotes, any special characters are output as-is "except \ \ and \ ' will be escaped output" only single quotes, backslashes are escaped
2, double quotes
The difference between single and double quotes
Double quotation marks replace the value of a variable, and single quotes treat it as a string output.
Support for escaping
Performance speed problem, because the string in double quotes needs to detect whether a variable containing the $ symbol decoration, in theory, the single quotation mark is relatively fast (single quotation mark efficiency is higher)
3, Heredoc
Heredoc can be understood not to use double quotes to define strings, but the effect is consistent with using double quotes. "Double quotation marks are equivalent to ordinary characters" (Long string)
Syntax requirements:
1, opening and closing tags use the same string, usually written in uppercase letters.
2. No spaces or extra characters can appear after the start tag.
3. The closing tag must be written on the head, not indented and blank, and there should be a semicolon at the end of the tag.
4. Variables located between the opening and closing tags can be parsed normally, but the function is not allowed.
The double quotation marks are just one ordinary character, and the other effect is consistent with the string effect of the double quotation marks.
Cases:
<?php$var = ' This is Suifeng '; Echo <<< "Eto" $var <br/> "666666" Eto
Output:
This is Suifeng
666666
4,Nowdoc
Similarly, Nowdoc is defined without using single quotes, but the effect is equivalent to a string defined using single quotation marks. "The single quotation marks are equivalent to ordinary characters at this time"
Data type
Three big data types "scalar, compliant, special"
Floating-point types
Floating-point types cannot be applied to comparison operators
Boolean type
Seven cases of false
Integer 0, floating point 0.0, Boolean false, empty string, 0 string, empty array, NULL
Array type
Hyper-Global Array
$GLOBALS
$_server
$_request
$_post
$_get
$_files
$_env
$_cookie
$_session
Null three cases
Variables that are directly assigned null, undefined variables, unset () destroyed
Constant
Defined
Const define
Const faster, is the language structure, define is the function
Define cannot be used for definition of class constants, const can, constants cannot be modified once defined, cannot be deleted
Predefined Constants (Magic constants)
__line__ : Returns the current line number in the file. Can also be written as __line__.
__file__: Returns the absolute path (including the file name) of the current file.
__dir__: Returns the absolute path (without the file name) of the current file, equivalent to dirname (__file__).
__function__: Returns the name of the current function (or method).
__class__: Returns the current class name (including the scope or namespace of the class).
__trait__: Returns the current TRAIT name (including the scope or namespace of the TRAIT).
__method__: Returns the current method name (including the class name).
__namespace__: Returns the name of the namespace for the current file.