Loading

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 ?> 

 

posted @ 2017-06-28 15:00  5572  阅读(82157)  评论(0编辑  收藏  举报