PHP remove commas from numeric strings

前端 未结 7 1441
悲哀的现实
悲哀的现实 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:44

    It sounds like the ideal solution for what you're looking for is filter_var():

    $a = filter_var($a, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND);
    

    (Note that it's using FILTER_VALIDATE_FLOAT instead of FILTER_VALIDATE_INT because that one doesn't currently have a FILTER_FLAG_ALLOW_THOUSAND option).

提交回复
热议问题