我正在使用递归来减少一个数字的值并将其等于另一个数字,但产生的结果是空白的,我找不到错误。
$A = 40;
$B = 130 ;
function Equalize( $A , $B ) {
if ( $B - $A >= 30 ) {
$Start = $A + 30 ;
Equalize($Start , $B );
}
else {
//if I place- echo 'A='.$A; here;
// then it echoes : A=130.but **return** doesn't works....???
return $A;
}
}
$Result = Equalize( $A , $B );
echo 'Final Result ='.$Result ; //here it shows result as empty
更新
$A = 40;
$B = 130 ;
function Equalize( $A , $B ) {
if ( $B - $A > 30 ) {
$Start = $A + 30 ;
Equalize($Start , $B ); **DO I NEED 'return' HERE TOO before function call ????**
}
else {
//if I place- echo 'A='.$A; here;
// then it echoes : A=100.but **return** doesn't works....???
return $A;
}
}
$Result = Equalize( $A , $B );
echo 'Final Result ='.$Result ; //here it shows result as empty