PHP settype() Function
settype()This function is used to set the type of a variable.
PHP Version Requirement: PHP 4, PHP 5, PHP 7
Syntax
bool settype ( mixed &$var , string $type )
Parameter Description:
$var: The variable to be converted.
$type: The possible values of type are.
- "boolean" (or "bool", as of PHP 4.2.0)
- "integer" (or "int", as of PHP 4.2.0)
- "float" (Only available after PHP 4.2.0, "double" used in older versions is now deprecated)
- "string"
- "array"
- "object"
- "null" (as of PHP 4.2.0)
Return Value
Returns TRUE on success, or FALSE on failure.
Example
Example
$foo = "5bar"; // string
$bar = true; // boolean
var_dump($foo);
var_dump($bar);
settype($foo, "integer"); //$foo is now 5 (integer)
settype($bar, "string"); //$bar is now "1" (string)
var_dump($foo);
var_dump($bar);
The output is:
string(4) "5bar" bool(true) int(5) string(1) "1"Other Extensions
PHP Available Functions