This is a simple PHP program where we need to calculate the sum of all digits of a number.
Input : 711 Output : 9 Input : 14785 Output : 25
In this program, we will try to accept a number in the form of a string and then iterate through the length of the string. While iterating we will extract the digit from each position and then add them to the previously extracted digit, thus getting the sum.
- PHP | Check if a number is Perfect number
- PHP | Check if a number is armstrong number
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- PHP | Ds\Sequence sum() Function
- PHP | Ds\Vector sum() Function
- PHP Ds\Map sum() Function
- PHP | Ds\Deque sum() Function
- PHP Ds\Set sum() Function
- PHP | Factorial of a number
- PHP | check if a number is Even or Odd
- PHP | Check if a number is prime
- PHP | Find the number of sub-string occurrences
- How to convert a string into number in PHP?
- Program to find the number of days between two dates in PHP
- PHP | Number of week days between two dates
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.