Beginners have never touched programming before. they have written a question about simple computing in a function. Function sum ($ num1, $ act, $ num2 ){
If ($ act! = '+' & $ Act! = '-' & $ Act! = '*' & $ Act! = '/'){
Echo $ res = null;
Exit;
} Elseif ($ act = '+ '){
$ Res = $ num1 + $ num2;
}
Elseif ($ act = '-'){
$ Res = $ num1-$ num2;
}
Elseif ($ act = '*'){
$ Res = $ num1 * $ num2;
}
Elseif ($ act = '/'){
If ($ num2 = 0 ){
Echo '0 cannot be used as the divisor,
';
} Else {
$ Res = $ num1/$ num2;
}
}
Return $ res;
}
Echo sum (10, '+', 2 );
?>
Why can we only calculate the addition, while $ act assigns '-' * '/' to calculate the result 12. thank you very much for pointing out the error.
Reply to discussion (solution)
All points of judgment
$ Act = '+'
It should be = rather than value assignment.
$ Act = '+'
$ Act = '-'
$ Act = '*'
$ Act = '/'
Change it now. OK! Thank you!