[英]PHP Intval() strange behaviour
I am currently trying to resolve a problem with changing the type of a variable in order to be able to do math operations with it. 我目前正在尝试解决更改变量类型的问题,以便能够对其进行数学运算。 I am trying to enhance a Wordpress plugin called "WooCommerce PDF Invoices & Packing Slips".
我正在尝试增强一个名为“ WooCommerce PDF发票和装箱单”的Wordpress插件。
There is a variable $item['order_price']
, which contains a price with a currency sign. 有一个变量
$item['order_price']
,其中包含带有货币符号的价格。 var_dump()
of this variable returns string(48)"709 Kč"
. 此变量的
var_dump()
返回string(48)"709 Kč"
。 When I try to get the integer value using either intval()
or casting it via (int)
, it returns 0
. 当我尝试使用
intval()
或通过(int)
强制转换获取整数值时,它返回0
。
What could be the solution? 有什么解决方案?
你试一试
filter_var($item['order_price'], FILTER_SANITIZE_NUMBER_INT);
我建议您至少使用:trim($ item ['order_price']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.