且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在PHP中将字符串转换为数字?

更新时间:2022-04-21 22:31:02

您通常不需要这样做,因为在大多数情况下,PHP都会为您强制类型.对于确实要明确转换类型的情况, 播放 它:

You don't typically need to do this, since PHP will coerce the type for you in most circumstances. For situations where you do want to explicitly convert the type, cast it:

$num = "3.14";
$int = (int)$num;
$float = (float)$num;