The function settype() will set a particular function to a specified type. The first parameter must be the variable which needs to be converted and the second parameter must be the type.
Supported types
“boolean” (or, since PHP 4.2.0, “bool”)
“integer” (or, since PHP 4.2.0, “int”)
“float” (only possible since PHP 4.2.0, for older versions use the deprecated variant “double”)
“string”
“array”
“object”
“null” (since PHP 4.2.0)
<?php $int = 25; $str = 'Hello world!'; $bool = true; $arr = array(1,2,3); $obj = new stdClass; $str2 = 'Hello World!'; settype($int, 'string'); settype($str, 'array'); settype($bool, 'integer'); settype($arr, 'object'); settype($obj, 'array'); settype($str2, 'null'); var_dump($int); echo '<br />'; var_dump($str); echo '<br />'; var_dump($bool); echo '<br />'; var_dump($arr); echo '<br />'; var_dump($obj); echo '<br />'; var_dump($str2); ?>
The result
string(2) “25″
array(1) { [0]=> string(12) “Hello world!” }
int(1)
object(stdClass)#2 (3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
array(0) { }
NULL
array(1) { [0]=> string(12) “Hello world!” }
int(1)
object(stdClass)#2 (3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
array(0) { }
NULL
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)


» Latest comments