3

I have a value like 12,25,246 I want to get 1225246 (must be an integer)

How can I do that?

I have searched a lot but there are direct answer like converting string to integer but not like this actually these both are like integer

I have tried php formate_number but it did not worked.

CodeBreaker
  • 395
  • 2
  • 9
  • It already answered, You will get it in more details over there: https://stackoverflow.com/questions/8529656/how-do-i-convert-a-string-to-a-number-in-php – Rajon Mar 24 '20 at 11:46
  • It's not the same. @Rajon – CodeBreaker Mar 24 '20 at 11:47
  • @Rajon The question is slightly different than the one you linked. Here the value has multiple commas and is not in a common numerical format. – segFault Mar 24 '20 at 11:49
  • 1
    Show us how you tried to solve the problem yourself, then show us exactly what the result was, and tell us why you feel it didn't work. Give us a **clear explanation of what isn't working** and provide [a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Read [How to Ask](http://stackoverflow.com/help/how-to-ask) a good question. Be sure to [take the tour](http://stackoverflow.com/tour) and read [this](https://meta.stackoverflow.com/q/347937/1011527). – Jay Blanchard Mar 24 '20 at 12:34
  • It is in JavaScript @MarkusZeller – CodeBreaker Mar 24 '20 at 13:12

2 Answers2

6

You could use a combination of intval() and str_replace() to do this.

Example:

$value = '12,25,246';
var_dump(intval(str_replace(',','',$value)));
// Yields: "int(1225246)"

Sandbox

segFault
  • 3,887
  • 1
  • 19
  • 31
1
$number = (int)str_replace(',', '', '12,25,246');

here is it

Pkchkchiseu
  • 253
  • 2
  • 3
  • 13