How to convert string to int in php

hzc
Release: 2023-03-01 15:56:02
Original
2881 people have browsed it

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

##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
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!

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!