Skip to content

Commit a951459

Browse files
committed
改进数组查询
1 parent c33edac commit a951459

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/db/concern/WhereQuery.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public function where($field, $op = null, $condition = null)
4848
$param = func_get_args();
4949
array_shift($param);
5050

51+
if (is_array($field) && is_array($field[0])) {
52+
$logic = is_string($op) && 'or' == strtolower($op) ? 'OR' : 'AND';
53+
return $this->parseWhereExp($logic, function($query) use($field) {
54+
foreach($field as $item) {
55+
$query->where($item[0], $item[1], $item[2]);
56+
}
57+
}, null, null);
58+
}
59+
5160
return $this->parseWhereExp('AND', $field, $op, $condition, $param);
5261
}
5362

@@ -91,6 +100,15 @@ public function whereOr($field, $op = null, $condition = null)
91100
$param = func_get_args();
92101
array_shift($param);
93102

103+
if (is_array($field) && is_array($field[0])) {
104+
$logic = is_string($op) && 'or' == strtolower($op) ? 'OR' : 'AND';
105+
return $this->parseWhereExp($logic, function($query) use($field) {
106+
foreach($field as $item) {
107+
$query->whereOr($item[0], $item[1], $item[2]);
108+
}
109+
}, null, null);
110+
}
111+
94112
return $this->parseWhereExp('OR', $field, $op, $condition, $param);
95113
}
96114

0 commit comments

Comments
 (0)