i have a function which gets the '>' or '<' operator sign as a parameter
now i need to use this parameter in if-else condition
i tried using eval but it always return true..
how should i go about with this?
| SitePoint Sponsor |
i have a function which gets the '>' or '<' operator sign as a parameter
now i need to use this parameter in if-else condition
i tried using eval but it always return true..
how should i go about with this?
flag it and use a control structure.
PHP Code:function do_something($flag=0) {
if($flag === 0) {
return '< operation';
} else {
return '> operation';
}
}
echo '<p>',do_something(),'</p>';
echo '<p>',do_something(1),'</p>';
Last edited by oddz; May 27, 2009 at 02:28.
Is this something similar to what you're attempting?
PHP Code:<?php
function compare($iLeftValue, $sOperator, $iRightValue)
{
switch (true)
{
case ($sOperator === '>'):
return ($iLeftValue > $iRightValue);
break;
case ($sOperator === '<'):
return ($iLeftValue < $iRightValue);
break;
default:
return false;
break;
}
}
compare(5, '>', 10); #false
compare(5, '<', 10); #true
?>
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
Bookmarks