Skip to content

Commit 4d1b458

Browse files
committed
改进数组查询
1 parent 6d8bcc8 commit 4d1b458

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/db/concern/WhereQuery.php

Lines changed: 19 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+
$where = function($query) use($field) {
53+
foreach($field as $item) {
54+
$query->where($item[0], $item[1], $item[2]);
55+
}
56+
};
57+
$logic = is_string($op) && 'or' == strtolower($op) ? 'OR' : 'AND';
58+
return $this->parseWhereExp($logic, $where, null, null);
59+
}
5160
return $this->parseWhereExp('AND', $field, $op, $condition, $param);
5261
}
5362

@@ -91,6 +100,16 @@ 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+
$where = function($query) use($field) {
105+
foreach($field as $item) {
106+
$query->whereOr($item[0], $item[1], $item[2]);
107+
}
108+
};
109+
$logic = is_string($op) && 'or' == strtolower($op) ? 'OR' : 'AND';
110+
return $this->parseWhereExp($logic, $where, null, null);
111+
}
112+
94113
return $this->parseWhereExp('OR', $field, $op, $condition, $param);
95114
}
96115

0 commit comments

Comments
 (0)