php - How to increment each digit in a variable by 5? -


i need php function adds 5 each number of string given , go 0 once reaches 10.

let's $number = 281621 , need 5 added each of digits, end result should like:

736176 

each digit should go 0 once reaches 10. how accomplish this?

this thing.

    function addtonumber($number, $add){         $string_number = strval($number);         for($i = 0; $i < strlen($string_number); $i++)             $string_number[$i] = strval((intval($string_number[$i]) + $add) % 10);         return intval($string_number);     }      $number = 281621;      echo addtonumber($number, 5);  ?> 

addtonumber() takes number self first argument , second argument number want add each digit, in case 5. it's pretty straight forward , don't think explanation required still if have doubts, leave in comments.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -