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

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -