Created
February 11, 2016 13:59
-
-
Save NEbere/63e77b1b485b2a0aaa27 to your computer and use it in GitHub Desktop.
Sum of the integers in a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function digitSum($n) { | |
$array = str_split($n); | |
$sum = array_sum($array); | |
print $sum; | |
} | |
//calling the function | |
digitSum("123"); | |
//returns 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment