PHP settype() Function
settype() The 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 convert.
-
$type: the possible values of type.
- "boolean" (or "bool", since PHP 4.2.0)
- "integer" (or "int", since PHP 4.2.0)
- "float" (only available after PHP 4.2.0; the "double" used in older versions is now deprecated)
- "string"
- "array"
- "object"
- "null" (since PHP 4.2.0)
Return Value
Returns TRUE on success, FALSE on failure.
Example
Example
The output is:
string(4) "5bar"
bool(true)
int(5)
string(1) "1"
Available PHP Functions