In a word, no.
In the paragraph, you can create an anonymous function to determine the value of your $value2 :
$value1 = 5; $op_and_value2 = function($value) { return $value1 / 2; }; echo $op_and_value2($value1);
Or you can make a class to encapsulate this behavior, but it works even more.
Or you can go to the dark side and use eval .
$value1 = 5; $value2 = "/ 2"; echo eval("return $value1 $value2;");
(If the "dark side" was not enough hint, do not do this if you do not want everyone to hate you.)
It would be best to store the operator and value2 separately (although you can still combine them into a structure); the operator is best stored as a function (perhaps an anonymous function, as mentioned above, but with two arguments, not hard code 2 ).
source share