Home >Backend Development >PHP Problem >How to convert string to int in php

How to convert string to int in php

hzc
hzcOriginal
2020-06-19 15:14:182957browse

How to convert string to int in php

#How to convert string to int in php?

Convert string to integer (int) intval() printf()

int

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

##intval

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

sprintf

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

Recommended tutorial: "

php tutorial"

The above is the detailed content of How to convert string to int in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn