PHP将格式化的int转换为int [英] php converting formatted int to int

查看:79
本文介绍了PHP将格式化的int转换为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉提出这个问题,但是,我找不到能解决这个问题的解决方案-> 7,000到7,000.

Sorry for asking this but, I cant found a solution that will get this -> 7,000 to 7000.

我正在使用intval()和number_format(),但这只会给我7而不是7000.

I'm using intval() and number_format() but it will just give me 7 not 7000.

$myVal = '7,000';
echo intval($myVal);

这将返回7

与number_format()相同

same goes with number_format()

我在做什么错了?

推荐答案

intval()由于逗号而无法与您使用的字符串一起使用.您可以使用str_replace()删除逗号,然后像这样调用intval():

intval() won't work with the string you have because of the comma. You can remove the comma by using str_replace() and then calling intval() like so:

echo intval(str_replace(',', '', $myVal))

这篇关于PHP将格式化的int转换为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆