Home > Backend Development > PHP Problem > How to convert php string to integer

How to convert php string to integer

爱喝马黛茶的安东尼
Release: 2023-02-23 13:22:01
Original
3840 people have browsed it

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 是整型 
?>
Copy after login

intval

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

sprintf

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template