Skip to content

Instantly share code, notes, and snippets.

@NEbere NEbere/sum.php
Created Feb 11, 2016

Embed
What would you like to do?
Sum of the integers in a string
<?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
You can’t perform that action at this time.