How do I find the sum of all the digits in a number in PHP?
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).
$number
2.1m questions
2.1m answers
60 comments
57.0k users