Type conversion in 1.PHP
Automatic conversion
Other type conversion numeric type
True->1
False->0
Null->0
' True '->0
' -3abc '->-3
' 3.123abc '->3.123
' 3e2av '->300
Other types convert to string type
numeric value itself
True->1
false-> empty string
null-> empty string
Array->array
Object->fatal error (fatal, cannot output object directly)
Resource->resource ID #数字
Convert other types to Boolean types
Convert to Boolean type false has
0->false
0.0->false
' or ' 0 '->false
Null->false
Array ()->false
Other will convert to True
Forced conversions
Temporary conversion
(int) | (integer)
(float) | (double) | (real)
(string)
(BOOL) | (Boolean)
(array)
(object)
(unset)
Implemented in the form of functions
Intval ($var)
Floatval ($var) |doubleval ($var)
Strval ($var)
Boolval ($var):P hp 5.5.0
Permanent conversion
BOOL Settype ($var, $type): Sets the type of the variable
Types of $type settings:
Int|integer
Float|double|real
String
Bool|boolean
Array
Object
Null
String GetType ($var): Gets the type of the variable
Common functions:
Var_dump ($var,...)
unset ($var,...)
Define constants:
Define ($name, $value [$ignore =false])
Const Name=value;
Use constants:
Direct constant Name
Constant ($NAME)
Detects if a constant name exists:
Defined ($name)
Get the defined constant name and value:
Get_defined_constants ()
Get Current version: Php_version
Get the current operating system: Php_os
Magic constants:
__LINE__: Gets the current line number
__FILE__: Absolute path to the current file
__DIR__: Get the absolute path where the file is located
__FUNCTION__:
__CLASS__:
__METHOD__:
__TRAIT__:
__NAMESPACE__:
Get the type of the variable:
Var_dump ()
GetType ()
The types of variables are detected by the variable function library:
Is_int () |is_integer () |is_long ()
Is_float () |is_double () |is_real ()
Is_string ()
Is_bool ()
Is_scalar ()
Is_null ()
Is_array ()
Is_object ()
Is_resource ()
Is_numeric ()
Ord ($char): Gets the ASCII of the specified character, returning the value of ASCII
Chr ($ASCII): Get the corresponding character based on ASCII
Summary of basic PHP knowledge