I'd like do something like this:
$type = "int"; $casted = ($type)$value;
This doesn't work. But is there some other way to cast to a dynamically determined type?
Thanks
Use the settype()
function.
http://php.net/manual/en/function.settype.php
Example:
$type = 'int'; $var = '20'; settype($var, $type); var_dump($var);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With