Use operator inside string.
Posted: Thu Jan 28, 2010 1:12 am
Hi there folks. Not sure if its possible, I'm trying to do a comparison of two values. However, the comparison operator is stored in a string. Here's what I'm trying to do.
I figured the above wouldn't work, but I'm wondering if there may be something as simple that can be done. If not I image the simplest course of action would be if..else if..else checks for each possible operator then doing the check I want to make.
Thanks in advance for any assistance.
Code: Select all
$oper = '>='; //given to me, op can be '<', '<=', '==', '>=', or '>'
$value1 = 10;
$value 2 = 15;
if($value1 $oper $value2) {
statements...
}Code: Select all
if($oper == '<') {
if($value1 < $value2) {
statements...
}
} else if($oper == '<=') {
if($value1 <= $vaule2) {
.....and so on