In PHP, I can do this:
$value1 = 5;
$value2 = -2;
echo $value1 + $value2; // 3
But how would I do this with multiplication or division? Something like:
$value1 = 10;
$value2 = /2;
echo $value1 (?) $value2; // 5;
How would I manage this situation as simply as possible?
If you only need to differentiate between division and multiplication,
$value2 = 2;
//or
$value2 = 1/2;
echo $value1 * $value2;
Your code works with addition and subtraction, because -2
in $value2 = -2;
does not mean "subtract two". It means "[add] minus two". For multiplication, you need "two" or "the inverse of two"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With