PHP settype() Function
❮ PHP Variable Handling Reference
Example
Convert variables to specific types:
<?php
$a = "32"; // string
settype($a, "integer"); // $a is now integer
$b = 32;
// integer
settype($b, "string"); // $b is now string
$c = true; //
boolean
settype($c, "integer"); // $c is now integer (1)
?>
Try it Yourself »
Definition and Usage
The settype() function converts a variable to a specific type.
Syntax
settype(variable, type);
Parameter Values
Parameter | Description |
---|---|
variable | Required. Specifies the variable to convert |
type | Required. Specifies the type to convert variable to. The possible types are: boolean, bool, integer, int, float, double, string, array, object, null |
Technical Details
Return Value: | TRUE on success, FALSE on failure |
---|---|
Return Type: | Boolean |
PHP Version: | 4.0+ |
❮ PHP Variable Handling Reference