Hello,
I am wondering if it is all possible to have a variable operate a math command like...
$set = '+';//$set comes from a database and it changes
echo (10 $set 4); // would return 14
This doesnt seem to work so I am wondering if I would have to do
if($set == '+'){ echo (10 + 4); }
if anyone can figure out how to do that other way please share, thanks.
It would be a big time saver since there are 6 of these
variables in math question
Moderator: General Moderators
-
Robert Plank
- Forum Contributor
- Posts: 110
- Joined: Sun Dec 26, 2004 9:04 pm
- Contact:
Code: Select all
$set = '+';//$set comes from a database and it changes
echo eval("return 10 $set 4;");there are only 2 things you need to know:
validation, so people don't request evil things from your string
evaluation of the expression
a very dirty sample can be found at
http://home.mysth.be/~timvw/programming ... ulator.txt
validation, so people don't request evil things from your string
evaluation of the expression
a very dirty sample can be found at
http://home.mysth.be/~timvw/programming ... ulator.txt