An easy question to ask, hope not to stupid.
$var=0;
$condition="$var!=0";
if($condition) {
# do something #
}
else {
# do something else #
}
Obviously the code up there doesn’t work as intended. Is there a nice way to obtain an if-condition from a string? Or do I have to parse the string in some disturbing way?
EDIT
I didn’t explain myself very well.
The fact is that the string could contain any possible condition you can immagine es:
- $var > 0
- $var < 0
- $var == 0
- etc
I read this condition from an xml file as a string, so I don’t know what I will find.
Just because no one has posted it yet. Ask yourself what comparisons need to be made. If they’re doing simple math operations you might want to have something in the schema like this.
It’ll allow you to have multiple conditions, should be relatively simple to parse and convert to php code.