The function settype() set or modifies the type of a variable.
bool settype ( mixed &$var , string $type )
Sr.No | Parameter | Description |
---|---|---|
1 |
var |
Mandatory. The variable being converted. |
2 |
type |
Mandatory. Specifies the type to convert var to.Possibles values of type are:
|
This function returns true on success or false on failure.
PHP 4 and above
Following example demonstrates use of function settype():
<?php $a = "tutorialspoint"; $b = true; echo "***Before settype****<br>"; var_dump($a); echo "<br>"; var_dump($b); echo "<br>"; settype($a, "integer"); // $a is now 0 (integer) settype($b, "string"); // $b is now "1" (string) echo "***After settype****<br>"; var_dump($a); echo "<br>"; var_dump($b); ?>
This will produce following result −
***Before settype**** string(14) "tutorialspoint" bool(true) ***After settype**** int(0) string(1) "1"