php - Put IF condition inside a variable -


Is there any way to put conditions within any one variable and then use that variable in an if statement? See the examples given below:

  $ value1 = 10; $ Value2 = 10; $ Value_condition = '($ value1 == $ value2)'; If ($ value_condition) {echo 'this works!'; } Else {echo 'it does not work'. '; }  

I think this may be a strange question that I'm learning the basics of PHP

There is no need to use strings. Use it directly like this:

  $ value1 = 10; $ Value2 = 10; $ Value_condition = ($ value1 == $ value2); If ($ value_condition) {echo 'this works!'; } Else {echo 'it does not work'. '; }  

Or to evaluate, you can use this type using " because it {...} .

I think it can work! Besides, using eval () is bad! Make sure you use it in the right place, where you are sure input for any other eval () function!


Comments