I am working on php bcmath extention for factorial calculation and i find that echo and return cause different result
This Code generate wrong result
<?php
$a = 25;
function test($a){
if($a>1){
$sum = bcmul($a, test($a-1)) ;
echo $sum;
}
if($a == 1) { return $a ;}
}
test($a); // Output 200000000000000000000000
?>
while below code generate correct result
<?php
$a = 25;
function test($a){
if($a>1){
$sum = bcmul($a, test($a-1)) ;
return $sum;
}
if($a == 1) { return $a ;}
}
echo test($a);
?>
this problem generate 200000000000000000000000 result with echo $sum and return wrong result but if i echo test() and return $sum then it tend to right result 15511210043330985984000000. why