PHP中将字符串转化为整数(int) intval() printf()

int

1 <?php 
2 $foo = "1"; // $foo 是字符串类型 
3 $bar = (int)$foo; // $bar 是整型 
4 ?> 

intval

1 <?php 
2 $foo = "1"; // $foo 是字符串类型 
3 $bar = intval($foo); // $bar 是整型 
4 ?> 

sprintf

1 <?php 
2 $foo = "1"; // $foo 是字符串类型 
3 $bar = sprintf("%d", $foo); // $bar 是字符串类型 
4 ?> 
原文地址:https://www.cnblogs.com/zsczsc/p/7089746.html