Function not working as expected in PHP -
what wrong output of function, prints out inf int browser expected print out 654321 exact same function written in c# print out expected result.
<?php function reverse($n, $r){ if($n == 0) { return $r; } return reverse($n/10, $r*10 + $n%10); } echo reverse(123456, 0); ?>
it not integer division. in c# deal strict typing, , when divide 25 4 in c# integer result, 6. in php 6.25, float result.
try intval
results before recursion integer division
Comments
Post a Comment