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

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -