Constant
Defined:
Form One
// define("PI",常量值);define("PI",3.14);define("school","讲理");
Form Two
// 定义形式二const1234;const"abcd";
Use:
Ps:
- Infer whether a constant exists: use
defined(常量名)
function inference.
- Use a constant that is not defined: in PHP, an error occurs when using a variable and constant that is not defined. Instead of outputting a value that does not define a variable, it outputs a value that does not have a constant defined, and its value is the constant name.
Defining constants in advance
Magic Constants
definition: In fact, it is just a constant form. But there is no constant "constant", its value will actually change, is only a few of the few:
- _file_: Represents the full physical path of the current Web page file
- _dir_: Represents the directory where the current Web page file resides
- _line_: Represents the "line number" where the variable name is currently located
Data type
Integer type
Floating-point types:
String
Four different forms:
$str1"字符串内容...";$str2‘字符串内容...‘;$str3 = <<<"标识符A"字符串内容标识符A;$str4 = <<<"标识符B"字符串内容标识符B;
Single-argument string:
// 单引號字符串。=,须要转义或能够识别的转义符有:\和‘$str1‘abcdefg‘;
Double-argument string:
// 双引號字符串,须要转义或能够识别的特殊符号有:\,",\n,\r(回车符),\t(tab符),$。
// 事实上就是取消了其在双引號字符串中的变量的“起始含义”$str2"abcdefg";
Double-argument delimiter string:
// 双引號定界字符串,须要转义能够识别的特殊符号有:\n,\,//\r,\t。双引號和单引號能够直接写出$str4=<<<"ABCD"abcdef,这里事实上就是字符串的内容ABCD;
Attention:
- The above identifier is our own "name" to obtain a similar constant name, can be arbitrary;
- The end line of the string, only the identifier itself and a semicolon can appear. Nothing else can appear, including spaces;
- The two arguments of the above identifiers can be omitted (not recommended);
- Identifiers are just a form that can recur.
Single-Quote bound string:
// 单引號定界字符串,没有须要转义或者能够识别的特殊字符$str3=<<<‘ABCD‘abcdef,这里事实上就是字符串的内容ABCD;
Boolean type (only two data: TRUE or FALSE)
Word: Bool,boolean
Common use Forms
Type conversions
Self-motivated conversions:
In any operation, it is assumed that some kind of data is required. The data given is not of that type. It usually happens that you have an active type conversion,
Analogy: Octdec (), Bindec () ...
in PHP. Arithmetic operators (including-,*,/,%) are simply calculations of values, such as
$sum"1""2"// sum的值就是3
-
Enforces type conversions:
? is determined by the "operator" operation at the time of the self-initiated type conversion, and the coercion type conversion is the display of the target data type through syntax:
//in the form of: (data type to convert) data $i = Span class= "Hljs-number" >10 ;
$s = (string) $i ;
-
Common conversion target types are: (int), (float), (string), (bool), (array), (object)
-
Change the data type of the original variable:
? The above coercion type conversion does not change the data type of the variable itself. Accordingly, there is a syntax that directly alters the data type of the original variable:
settype ($ variable name, " target type );
Type-related functions:
- Var_dump (): "Complete information" for the output variable. Almost only for debugging code;
- GetType ($ variable name): Gets the type name of the variable, returns a string representing the name of the type, for example: "String:," bool "," double ".
。。。
- SetType ($ variable name, "target Type");
- Isset (), Empty (), Nuset ().
- IS_XX type ($ variable name): series function to infer whether it is a data type
- Is_int ();
- Is_string ();
- Is_bool ();
- Is_float ();
- Is_numeric (); Infer whether it is a number
- Is_scalar (); Infer whether it is a scalar
- Is_array ();
- Is_object ();
- Is_null (); Infer whether it is empty
PHP constants, defining constants in advance, magic constants, and basic data types