Skip to content

Commit

Permalink
改进数组查询
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Nov 12, 2024
1 parent c33edac commit a951459
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/db/concern/WhereQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ public function where($field, $op = null, $condition = null)
$param = func_get_args();
array_shift($param);

if (is_array($field) && is_array($field[0])) {
$logic = is_string($op) && 'or' == strtolower($op) ? 'OR' : 'AND';
return $this->parseWhereExp($logic, function($query) use($field) {
foreach($field as $item) {
$query->where($item[0], $item[1], $item[2]);
}
}, null, null);
}

return $this->parseWhereExp('AND', $field, $op, $condition, $param);
}

Expand Down Expand Up @@ -91,6 +100,15 @@ public function whereOr($field, $op = null, $condition = null)
$param = func_get_args();
array_shift($param);

if (is_array($field) && is_array($field[0])) {
$logic = is_string($op) && 'or' == strtolower($op) ? 'OR' : 'AND';
return $this->parseWhereExp($logic, function($query) use($field) {
foreach($field as $item) {
$query->whereOr($item[0], $item[1], $item[2]);
}
}, null, null);
}

return $this->parseWhereExp('OR', $field, $op, $condition, $param);
}

Expand Down

0 comments on commit a951459

Please sign in to comment.