本文整理匯總了PHP中Operator::getOperator方法的典型用法代碼示例。如果您正苦於以下問題:PHP Operator::getOperator方法的具體用法?PHP Operator::getOperator怎麽用?PHP Operator::getOperator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Operator
的用法示例。
在下文中一共展示了Operator::getOperator方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: convertToPostfix
public function convertToPostfix()
{
require_once "operator.php";
require_once "operand.php";
if (!$this->validateInfix()) {
throw new Exception("Infix equation invalid.");
return false;
}
if (isset($postfix)) {
throw new Exception("Postfix already calculated");
return false;
}
$postfix = array();
$infixArray = explode(' ', $this->infix);
$operatorStack = array();
//Used as a LIFO stack for the operators
for ($i = 0; $i < count($infixArray); $i++) {
//Iterate through each element of the infix equation
$value = $infixArray[$i];
if (preg_match("/\\[[A-Za-z0-9]+\\]/", $value)) {
$postfix[] = new Variable($value);
} else {
if (preg_match("/[0-9]+/", $value)) {
$postfix[] = new Number($value);
} else {
$operator = Operator::getOperator($value);
if ($operator === false) {
throw new Exception("Operation is invalid.");
return false;
}
if (count($operatorStack) == 0 || !end($operatorStack) instanceof Operator && end($operatorStack) == LEFT_PARENTHESIS) {
$operatorStack[] = $operator;
} else {
if (!$operator instanceof Operator && $operator == LEFT_PARENTHESIS) {
$operatorStack[] = $operator;
} else {
if (!$operator instanceof Operator && $operator == RIGHT_PARENTHESIS) {
$currentOperator;
do {
$currentOperator = array_pop($operatorStack);
$postfix[] = $currentOperator;
} while (!$currentOperator instanceof Operator && $currentOperator != LEFT_PARENTHESIS);
array_pop($operatorStack);
} else {
if ($operator->getPrecedence() > end($operatorStack)->getPrecedence()) {
$operatorStack[] = $operator;
} else {
if ($operator->getPrecedence() == end($operatorStack)->getPrecedence()) {
$postfix[] = array_pop($operatorStack);
$operatorStack[] = $operator;
} else {
if ($operator->getPrecedence() < end($operatorStack)->getPrecedence()) {
$postfix[] = array_pop($operatorStack);
} else {
throw new Exception("Invalid operation.");
return false;
}
}
}
}
}
}
}
}
}
while (count($operatorStack) > 0) {
$postfix[] = array_pop($operatorStack);
}
$this->postfix = $postfix;
}
示例2: Operator
if ($uflag == false && $pflag == false) {
// Mounting sql statement
$sql = "SELECT * FROM User WHERE userId='{$name}' ";
if (!$operatorLogged) {
$sql .= " AND password = OLD_PASSWORD('{$pwd}')";
}
$dbusercat->query($sql);
$count = $dbusercat->numRows();
if ($count == 0) {
$aflag = true;
$_SESSION['userTry'] += 1;
$mensagemErro = "<font color=red><b>Usuário e/ou senha incorretos.</b></font>";
}
if ($operatorLogged) {
$objOp = new Operator($dbcat);
if (!$objOp->getOperator($operator, $pwd)) {
$aflag = true;
$_SESSION['userTry'] += 1;
}
}
if (!$aflag) {
$oflag = true;
$row_array = $dbusercat->fetchRow();
$dbusercat->freeResult();
if (isset($_SESSION['userLang'])) {
$lang = $_SESSION['userLang'];
}
if ($userLogged) {
$_SESSION = array();
session_destroy();
session_regenerate_id();