Php 在if条件下,使用条件运算符传递后置值

Php 在if条件下,使用条件运算符传递后置值,php,if-statement,conditional-statements,conditional-operator,Php,If Statement,Conditional Statements,Conditional Operator,我想从表单输入中发布条件运算符。在IF条件下,使用POST运算符。无法使用任何逻辑将其完成 <form action="" method="post" accept-charset="utf-8"> <input name="postvalue" size="5" maxlength="7" value=">=5"> <p><input type="submit" value="Go"></p&

我想从表单输入中发布条件运算符。在IF条件下,使用POST运算符。无法使用任何逻辑将其完成

<form action="" method="post" accept-charset="utf-8">
        <input name="postvalue"  size="5" maxlength="7" value=">=5">
            <p><input type="submit" value="Go"></p>
</form>

<?php 
if(10 $_POST["postvalue"]) {
    echo "Its greater than 5";
} else {
    echo "Its less than 5";
}


?>


您可能正在寻找以下内容:

<form action="" method="post" accept-charset="utf-8">
        <input name="term"  size="5" maxlength="7" value=">=5">
            <p><input type="submit" value="Go"></p>
</form>

<?php 
// separate operator and operand from the posted value
preg_match('/^([=<>!]+)([0-9]+)$/', $_POST['term'], $tokens);
$operator = $tokens[1];
$operand  = $tokens[2];

// create an evaluation function
$check = create_function('$value', '
    $operand = '.$operand.';
    switch("'.$operator.'") {
    case "==": return ($value==$operand);
    case "!=": return ($value!=$operand);
    case "<":  return ($value<$operand);
    case "<=": return ($value==$operand);
    case ">":  return ($value>$operand);
    case ">=": return ($value>=$operand);
    default:   throw new Exception("invalid operator");
  }');

// apply the evaluation function to some value
try {
  if ($check(10)) {
      echo "10 is greater than 5";
  } else {
      echo "10 is less than 5";
  }
} catch (Exception $e) {
  echo sprintf('Exception: %s', $e->getMessage());
}
?>


啊,我明白了。。。你需要为此创建一个函数…嘿,这有错误,但你理解我的要求。我希望我需要一些像这样或类似于你的逻辑,我正在努力工作。经过一些最后的调整后很好。