programming-examples/php/Basics/PHP program to add the digits of a positive integer repeatedly until the result has a single digit..php
2019-11-18 14:44:36 +01:00

16 lines
231 B
PHP

<?php
function add_digits($num)
{
if ( $num > 0)
{
return ($num - 1) % 9 + 1;
}
else
{
return 0;
}
}
print_r(add_digits(48)."\n");
print_r(add_digits(59)."\n");
?>