I was wondering if it would be possible to do this:
$var = '$something == $somethingelse';
if ($var) { // Say hello }
and have it mean the same thing as this:
if ($something == $somethingelse) { // Say hello }
I know this will not work at the moment, because if ($var) checks to see if $var is set or not. But what I’m asking is: is there a method to allow this? Would appreciate an answer.
EDIT:
Basically I feel I should explain why I am doing this.
I want users to be able to control when they get a notification, based off some data that one of their “channels” has saved.
For instance, a user only wants to get a notification when their collected data is bigger than 60. So I would get them to choose two fields:
First field input of their number (int or float)
Second field choises (equals, <, >, =<, =>)
The last thing in this if statement would be their data collected by their “channel”.
I then want to be able to save their choice in a database, somehow, and then later act upon their choices.
You say this string is being generated by you elsewhere. I suggest, instead of generating a string, generate an array.
Like this:
array('something','==','somethingelse').Now when you want to process this, you can replace the variables with their values, and then check the operator and run the correct operation.
Something like this:
DEMO: http://codepad.org/vaELABEm
You can even use this to do other things, by adding more
cases to theswitch.