casting - PHP - Cast type from variable -
i asking myself if it's possible cast string become type defined before
e.g.
$type = "int"; $foo = "5"; $bar = ($type) $foo; and $bar === 5
yes, there's built-in function that:
$type = "int"; $foo = "5"; $bar = settype($foo, $type); documentation: http://php.net/manual/en/function.settype.php
Comments
Post a Comment