Answer the question
In order to leave comments, you need to log in
How to put an unknown mathematical sign between two arrays?
there is a code like this <?php echo $a + $b ?> which outputs addition. now you need to do what would be displayed not +, but what is in the array $ c. there can be +, -, *, /.
how to make it so that instead of the + sign, an unknown mathematical sign, aka $c , is displayed?
thanks in advance!
Answer the question
In order to leave comments, you need to log in
function doAction($a, $b, $action) {
switch ($action) {
case "+": return $a + $b;
case "-": return $a - $b;
case "*": return $a * $b;
case "/": return $a / $b;
default: throw new \BadFunctionCallException("Unknown action");
}
}
Hm) Cool question.
Only the function with the switch came to mind, like Immortal_pony.
https://wiki.php.net/rfc/operator-overloading
Through class creation and operator overloading!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question