PHP:转换为动态确定的类型 [英] PHP: casting to a dynamically determined type
本文介绍了PHP:转换为动态确定的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做这样的事情:
$type = "int";
$casted = ($type)$value;
这不起作用。但是还有其他方法可以强制转换为动态确定的类型吗?
This doesn't work. But is there some other way to cast to a dynamically determined type?
谢谢
推荐答案
使用 settype()
函数。
示例:
$type = 'int';
$var = '20';
settype($var, $type);
var_dump($var);
这篇关于PHP:转换为动态确定的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文