PHP remove commas from numeric strings

前端 未结 7 1454
悲哀的现实
悲哀的现实 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 12:38

    Do it the other way around:

    $a = "1,435";
    $b = str_replace( ',', '', $a );
    
    if( is_numeric( $b ) ) {
        $a = $b;
    }
    

提交回复
热议问题