Get the sum of all digits in a numeric string

array_sum(str_split($number));

This assumes the number is positive (or, more accurately, that the conversion of $number into a string generates only digits).

Leave a Comment