programming-examples/php/_Basics/PHP program to add the digits of a positive integer repeatedly until the result has a single digit..php

16 lines
231 B
PHP
Raw Normal View History

2019-11-15 12:59:38 +01:00
<?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");
?>