'<','let'=>'<=','gt'=>'>','get'=>'>=','eq'=>'=','neq'=>'<>');
foreach ($infoSearch as $term => $value) {
if (empty($value)) continue;
$name = $term;
if (strpos($term,"or_") !== false) { //添加or连接符
$terms['u<a href="https://www.52php.cn/tag/SEO/" title="SEO">SEO</a>r'] = true;
$name = str_replace("or_","",$term);
}
if (strpos($name,"in_") !== false) {
$terms['name'] = str_replace("in_",$name);
$terms['charCal'] = " in ";
$terms['value'] = "('" . implode("','",$value) . "')";
} else {
$terms['name'] = $name;
$terms['charCal'] = " like ";
$terms['value'] = "'" . trim($value) . "%'";
}
//放在else后面
foreach($separator as $charCalName =>$charCalVal){
if (strpos($name,$charCalName."_") !== false) {
$terms['name'] = str_replace($charCalName."_",$name);
$terms['charCal'] = $charCalVal;
$terms['value'] = "'" . trim($value) . "'";
}
}
$aryRst[] = $terms;
unset($terms);
}
return $aryRst;
}
function whereOperator($has_where,$uSEOr) {
$operator = $has_where ? ($uSEOr === false ? ' AND ' : ' OR ') : ' WHERE ';
return $operator;
}
/**
- aryTerm transArrayTerms转化后的查询条件
- @过滤没有输入的sql查询条件并转化成where条件.
*/
function getWhereSql($aryTerm) {
$whereCause = '';
if (count($aryTerm) > 0) {
$has_where = '';
foreach ($aryTerm as $value) {
$has_where = whereOperator($has_where,isset($value['uSEOr']));
$whereCause .= $has_where . $value['name'] . $value['charCal'] . $value['value'];
}
}
return $whereCause;
}