Specific methods:
(Video tutorial recommendation: php video tutorial)
1, forcing type conversion mode
Forced type conversion is a way of "putting the target type in parentheses before the variable to be converted" (from the "Type Skills" section of the PHP manual).
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
$ foo = " 1 "; // $foo is a string type.
$ bar =(int)$ foo; // $bar is an integer
& gt for integers, the conversion type name is int or integer.
2. Built-in function mode
The way to build a function is to use PHP's built-in function intval to convert variables.
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
$ foo = " 1 "; // $foo is a string type.
$ bar = intval($ foo); // $bar is an integer
& gt3. Format string mode
The way to format the string is to format the specified variable with sprintf's %d to achieve the purpose of type conversion.
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
$ foo = " 1 "; // $foo is a string type.
$bar = sprintf("%d ",$ foo); // $bar is a string type
& gt Strictly speaking, the conversion result of sprintf is still a string type, so it should not be regarded as a way to convert a string into an integer. But the string value he processed has indeed become "an integer that is forcibly converted into a string type".