Home  >  Article  >  Backend Development  >  How to convert php string to integer

How to convert php string to integer

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-08-29 15:07:233789browse

How to convert php string to integer

Convert strings to integers (int), intval(), and printf() in PHP.

Related recommendations: "PHP Tutorial"

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 是字符串类型 
?>

The above is the detailed content of How to convert php string to integer. 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