settype
settype
Set the type of a variable
bool **settype** mixed $var string $type
Set the type of variable to
.
var``type
varThe variable being converted.
type
Possibles values of are:
`type`- "boolean" or "bool"
- "integer" or "int"
- "float" or "double"
- "string"
- "array"
- "object"
- "null"
return.success
Throws a if the value of
is not a valid type, as of PHP 8.0.0.
Prior to PHP 8.0.0, a was emitted
and false was returned.
type``E_WARNING
Voorbeeld: example
<?php
$foo = "5bar"; // string
$bar = true; // boolean
settype($foo, "integer"); // $foo is now 5 (integer)
settype($bar, "string"); // $bar is now "1" (string)
var_dump($foo, $bar);
?>
Opmerking: > Maximum value for "int" is .
PHP_INT_MAX
gettypetype-castingtype-juggling