In php, you can use the settype() function to set the variable type, the syntax is "settype($var,"data type")"; the data type value can be "boolean", "integer", "float" , "string", "array", "object", "null".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, you can use settype () function to set the variable type.
The settype() function is used to set the data type of a variable. (Version requirements: PHP 4, PHP 5, PHP 7)
Syntax:
settype ( $var , $type ) //将变量var类型设置成type类型
Possible values of $type are:
"boolean" (or "bool" since PHP 4.2.0)
"integer" (or "int" since PHP 4.2.0)
"float" (only available after PHP 4.2.0, "double" used in older versions is now deprecated)
"string "
"array"
"object"
"null" (from PHP 4.2 .0)
Return value: TRUE when the setting is successful, FALSE when the setting fails.
Example:
<?php $foo = "5bar"; // string $bar = true; // boolean settype($foo, "integer"); // $foo is now 5 (integer) settype($bar, "string"); // $bar is now "1" (string) ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to set variable type in php. For more information, please follow other related articles on the PHP Chinese website!