vendredi 20 juillet 2018

How to get sum of all numbers/Digits in the string using PHP

I want to sum all values (i.e the values are digits/numbers) from the string. The string contain both numbers and string.

For example the string is

"h 23 w 43 l 23 df 45 gs 5g"

I want the total sum of above digit only

"125"

I sum all integer in the array. for example

"b24 s3 4"

first 24 is take as a double digit. And the second and third digit as a single digit value.

Please answer quickly.




Aucun commentaire:

Enregistrer un commentaire