In a word, no.
In a paragraph, you could create an anonymous function to capture the meaning of your $value2
:
$value1 = 5;
$op_and_value2 = function($value) {
return $value1 / 2;
};
echo $op_and_value2($value1); # 2
Or you could make a class to encapsulate this behaviour, but that's even more work.
Or you can go to the dark side, and use eval
.
$value1 = 5;
$value2 = "/ 2";
echo eval("return $value1 $value2;"); # 2
(If "dark side" wasn't hint enough, don't do this unless you want everyone to hate you.)
A better approach all around would be to store operator and value2 separately (although, you can still put them into a structure together); the operator would be best stored as a function (perhaps an anonymous function like above, but with two arguments, and not a hard-coded 2
).