I'm trying to check a string using <, >, ==, etc operators. I have a variable $var[1] that will equal "lt" to check for <. "gt" to check for >, "gte" to check for >=, "e" to check for ==, and so forth. What I'd like to do is use a switch statement to determine which operator to use, load it into a variable, then rather than saying
if($this < $that)
I can say
if($this $action $that) where $action equals < (for example)
My code is below. When I add in $action, I get an unexpected T_VARIABLE. Maybe someone can help me out with this, or help me with a beter way to do this?
switch($var[1])
{
case "lt":
$action = '<';
break;
case "lte":
$action = "<=";
break;
case "gt":
$action = ">";
break;
case "gte":
$action = '>=';
break;
case "e":
$action = "==";
break;
}
if( strlen($this->method[$val["name"]]) $action $var[0] )
{
// Check is okay
}
else
{
$this->setError($error);
}
BTW action is always set properly.