php中string如何转int-PHP问题

资源魔 20 0

php中string若何转int?

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

int

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

intval

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

sprintf

<?php 
     $foo = "1"; // $foo 是字符串类型 
     $bar = sprintf("%d", $foo); // $bar 是字符串类型 
?>

保举教程: 《php教程》

以上就是php中string若何转int的具体内容,更多请存眷资源魔其它相干文章!

标签: php php教程 php故障解决 php使用问题

抱歉,评论功能暂时关闭!