PHP remove commas from numeric strings

前端 未结 7 1466
悲哀的现实
悲哀的现实 2020-11-30 12:21

In PHP, I have an array of variables that are ALL strings. Some of the values stored are numeric strings with commas.

What I need:

A way to trim the comma

7条回答
  •  星月不相逢
    2020-11-30 13:02

     function cleanData($a) {
    
         if(is_numeric($a)) {
    
         $a = preg_replace('/[^0-9,]/s', '', $a);
         }
    
         return $a;
    
    }
    

提交回复
热议问题