<?php
function sumDigits($num, $base = 10) {
    $s = base_convert($num, 10, $base);
    foreach (str_split($s) as $c)
        $result += intval($c, $base);
    return $result;
}
echo sumDigits(1), ;
echo sumDigits(12345), ;
echo sumDigits(123045), ;
echo sumDigits(0xfe, 16), ;
echo sumDigits(0xf0e, 16), ;
?>