【发布时间】:2013-02-28 01:33:08
【问题描述】:
我有一个混合值数组:
$row = array('Unspecified risk','Yes','8','3','2','13','none','-1,49','-2,51','-1,46','-1,54'); -1,94 -1,55
如您所见,它包含文本以及正负逗号数字。
我需要将数值转换为正确的数字格式并保持文本值不变。
现在我正在遍历这些值:
foreach ($row as $value) {
// If $value is numeric, convert it to the
// right number format for use with MySQL (decimal(10,2))
// If not, leave it be.
}
我调查过两个相关问题,但找不到合适的解决方案。
- Converting a number with comma as decimal point to float
- I need php regular expression for numeric value including "-" and ","
谁能提供一个实际的例子?
【问题讨论】:
标签: php regex number-formatting